Tutorialsplane

PHP Check that variable is an array


PHP Check that variable is an array : PHP function is_array is used to check a variable whether it is array or not. it accepts one parameter as variable and finds it is array or not. Returns true if the variable is array else it returns false. Here we are going to explain this function with example –


PHP Check that variable is an array

Here is an example of how to check a variable is array or not –

PHP Check that variable is an array Example 1

$array = array('a', 'b', 'c');

if(is_array($array)){
echo "This is array.";
}else{
echo "This is not array.";
}
//will print - This is array

The above example will print – This is array because we passed array variable to check.

Now lets go with another example which is not array

PHP Check that variable is an array Example 1

$str = "abcd";

if(is_array($str)){
echo "This is array.";
}else{
echo "This is not array.";
}
//will print - This is not array

The above example will print – This is not array because we passed string variable to check and this function will refurn false so it will go in else condition.

PHP String Functions