PHP array functions are a very powerful set of functions. We can use these functions to sort, delete, and merge arrays. Today, we will introduce to you what role PHP array functions will play in our practical application. Hope to help beginners. If there is a... "> <LINKhref =" http://www.php100.com//statics/style/head
PHP array functions are a very powerful set of functions. We can use these functions to sort, delete, and merge arrays. Today, we will introduce to you what role PHP array functions will play in our practical application. Hope to help beginners.
If there is a large array and you need to find out whether it contains a specific element, you can use the PHP array function in_array (). The following example shows "Not found in this array", because Albert is searched in an array named $ namesArray, and such an element does Not exist in the $ namesArray array.
If there is a large array and you need to find out whether it contains a specific element, you can use the PHP array function in_array (). The following example shows "Not found in this array", because Albert is searched in an array named $ namesArray, and such an element does Not exist in the $ namesArray array.
-
- $ LookingFor = "Albert ";
-
- If (in_array ($ lookingFor, $ namesArray )){
-
- Echo "You 've got it! ";
-
- } Else {
-
- Echo "Not found in this array! ";
-
- }
-
- ?>
If You change the value of $ lookingFor to Mary, You will get "You 've got it !" Because Mary is an element in the $ namesArray array.
To count the number of elements in an array, simply use the PHP array function count:
-
- $ Countcount = count ($ namesArray);?>
The returned $ count value is 7.
You can add elements at the beginning or end of an array, or use the PHP array function array_merge () to create a new array containing two or more elements in the array, the order of elements is arranged in the specified order. if the original array is out of order, it needs to be re-ordered after merging.