Home Tutorial Php Phpbasics PHP Array Sub String Search


Share on Google+Share on Google+
PHP Array Sub String Search
Posted on: October 28, 2009 at 12:00 AM
PHP Array Sub String Search: In this tutorial you will learn how to search a sub string in an array. PHP provides in_array() function to search a sub string.

PHP Array Search Sub-String

In PHP if we need to search a sub-string within an array then we can use in_array() function. The format of in_array is much similar to array_search() function.

General Desciption of in_array() function is as follows:

General Format Boolean in_array ( mixed $search , array $array [, bool $strict ] )
Parameters $search: The value to be searched $array: The array in which the value to be searched $strict: If the value is set to true then the types of $search and $array will be checked
Return Value Return the key for $search if it is found in $array, otherwise false

PHP Search Array Substring Example 1:



echo"<br/><b>The value of \$array1 is:</b><br/>";



echo"<br/><b>The value to be search is \"$search\"</b><br/>";


    echo "The string: \"".$search."\" Found";


    echo"Not found";



The value of $array1 is:
array(4) {
  string(5) "India"
  string(4) "Land"
  string(2) "of"
  string(9) "diversity"

The value to be search is "India"
The string: "India" Found



Related Tags for PHP Array Sub String Search:

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 28, 2009

Recommend the tutorial

Advertisements Advertisements