If you have a large array, and you need to find out if it contains a specific element, you can use the PHP array function In_array (). The following example shows "not found in this array" because it looks for Albert in an array named $namesarray, and there is no such element in the $namesarray array.
- $ Namesarray = Array ("Joe", "Jane", "Bob", "Mary", "Paul", "Eddie", "John");
- $ lookingfor = "Albert" ;
- if (In_array ($lookingFor, $namesArray)) {
- echo "You ' ve found it!";
- } else {
- echo "Not found on this array!";
- }
- ?>
If you change the value of $lookingfor to Mary, you will get "you ve found it!" Information because Mary is an element in the $namesarray array.
If you want to count the number of elements in an array, simply use the PHP Array function count () to:
- $ Namesarray Array
- $ Count Count ?>
The value of the returned $count is 7.
You can add elements at the beginning or end of an array, or you can use the PHP array function array_merge () to create a new array containing two or more elements in the array, and when merging, the order of the elements will be arranged in the order specified, if the original array is ordered, It needs to be reordered after merging.
http://www.bkjia.com/phpjc/446331. HTML www.bkjia.com true http://www.bkjia.com/phpjc/446331.html techarticle If there is a large array, And you need to find out if it contains a specific element, you can use the PHP array function In_array (). The following example shows "not found in this ...