PHP Arrays: How to find an element in array using in_array

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


PHP in_array function is used to find if the element is present in the array as follows:

$new_array = array (1,2);

if (in_array(1, $new_array)){

print "1 is in the array";

}

This would return

"1 is in the array'.

in_array function checks if argument 1 variable is present in array in argument 2.





Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.