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

How to determine if a variable is an array in php

王林
Release: 2023-03-02 15:14:01
Original
7351 people have browsed it

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 )
Copy after login

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;;
}
?>
Copy after login

Output result:

变量 $arr_site 是一个数组
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template