Home  >  Article  >  Backend Development  >  How to determine if a variable is an array in php

How to determine if a variable is an array in php

王林
王林Original
2020-07-15 17:56:567252browse

The way PHP determines whether a variable is an array is through the is_array() function. Function syntax: [bool is_array(mixed $var)], if the detected variable is an array, it returns TRUE, otherwise it returns FALSE.

How to determine if a variable is an array in php

# To determine whether a variable is an array, you can use the is_array() function.

(Recommended learning: php tutorial)

Function introduction:

is_array() function is used to detect whether a variable is an array.

PHP version requirements: PHP 4, PHP 5, PHP 7

Function syntax:

bool is_array ( mixed $var )

Parameter description:

  • $ var: Variable to be detected

Return value

If the variable to be detected is an array, TRUE is returned, otherwise FALSE is returned.

Code implementation:

<?php
$arr_site = array(&#39;Google&#39;, &#39;Runoob&#39;, &#39;Facebook&#39;);
if(is_array($arr_site)){
    echo &#39;变量 $arr_site 是一个数组&#39;;
} else {
    echo &#39;变量 $arr_site 不是一个数组&#39;;
}
?>

Output result:

变量 $arr_site 是一个数组

The above is the detailed content of How to determine if a variable is an array in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn