Home > Article > Backend Development > How to determine if a variable is an array in php
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.
# 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('Google', 'Runoob', 'Facebook'); if(is_array($arr_site)){ echo '变量 $arr_site 是一个数组'; } else { echo '变量 $arr_site 不是一个数组'; } ?>
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!