AllInWorld99 provides a reference manual covering many aspects of web programming, including technologies such as HTML, XHTML, CSS, XML, JavaScript, PHP, ASP, SQL,FLASH, jQuery, java, for loop, switch case, if, if else, for...of, for...in, for...each,while loop, blogger tips, blogger meta tag generator, blogger tricks, blogger pagination, client side script, html code editor, javascript editor with instant output, css editor, online html editor, materialize css tutorial, materialize css dropdown list,break, continue statement, label,array, json, get day and month dropdown list using c# code, CSS button,protect cd or pendrive from virus, cordova, android example, html and css to make android app, html code play,telerik show hide column, Transparent image convertor, copy to clipboard using javascript without using any swf file, simple animation using css, SQL etc. AllInWorld99 presents thousands of code examples (accompanied with source code) which can be copied/downloaded independantly. By using the online editor provided,readers can edit the examples and execute the code experimentally.


Search array in php

Check array value in php

     PHP having some in-built function to check the value is exists or not in array.
  1. in_array()
  2. array_search()

in_array()

     This function will check the given value with array and if it the value is exists in the array, return true otherwise return false.


in_array(your_value,array,strict);

i) Simple Array

     The following example will tell you, how to check the value is exists or not in simple array.

$place=array("mulagumoodu","India","Tamilnadu","USA");

if(in_array("USA",$place))
{
  echo "USA Found in $place Array";
}
else
{
  echo "USA Not Found in $place Array";
}

Output:
USA Found in $place Array

ii) Associative Array

Associative array also similarly works simple array.

$place=array(0=>"mulagumoodu",1=>"India",2=>"Tamilnadu",3=>"USA");

if(in_array("USA",$place))
{
  echo "USA Found in $place Array";
}
else
{
  echo "USA Not Found in $place Array";
}

Output:
USA Found in $place Array


array_search()

     This function is used to find the given value is exists or not in an array and if exists return the key value otherwise return NULL.

array_search(your_value,array,strict);

Example

$place=array(0=>"mulagumoodu",1=>"India",2=>"Tamilnadu",3=>"USA");
echo array_search("USA",$place);

Output:
3



0 comments:

Post a Comment

Total Pageviews