PHP is_array() Function Example

PHP Script:


<?php
$test_var = "phptutors";
$checking_status = is_array($test_var);
echo $checking_status?"It's an array":"It's not an array";

echo "<br>";

$test_array = array("php","is_array","function");
$checking_status = is_array($test_array);
echo $checking_status?"It's an array":"It's not an array";
?>

Output:


It's not an array
It's an array

Description:

PHP is_array() function checks whether the given variable is an array or not and
return true when the variable is an array or false when the variable is not an array as shown in above example
we use $checking_status in a ternary expression if it is true "It's an array" message print
and if it is false "It's not an array" message print.

PHP is_array function parameters:

1- Variable: Specifies the variable which is going to checked by is_array function.

2 comments

  1. Pingback: PHP Arrays Example | PHP Tutors
  2. Pingback: Prevent Warning Invalid argument supplied for foreach | PHP Tutors

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s