Home  >  Article  >  Backend Development  >  What is the function in php to determine whether it is an array?

What is the function in php to determine whether it is an array?

青灯夜游
青灯夜游Original
2022-06-28 15:16:122915browse

The function in php to determine whether it is an array is "is_array()". The is_array() function can determine whether a specified variable is an array type. The syntax is "is_array($variable name)"; if the return value is true, the specified variable is an array. If the return value is false, the specified variable is not an array.

What is the function in php to determine whether it is an array?

The operating environment of this tutorial: windows7 system, PHP8.1 version, DELL G3 computer

In php, I want to determine whether a variable For an array, you can use the is_array() function.

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

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

Judgment syntax:

is_array($变量名)

is_array() The return value of the function is a Boolean type :

  • If the return value is true, the specified variable is an array

  • If the return value is false, the specified variable is not an array.

Judgment example:

<?php
header(&#39;content-type:text/html;charset=utf-8&#39;);   
function f($val){
	if(is_array($val)){
		echo "该变量是数组类型<br>";
	}else{
		echo "该变量不是数组类型<br>";
	}
}
$a = array(1,2,3,4,5);
$b = 123;
f($a);
f($b);
?>

What is the function in php to determine whether it is an array?

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the function in php to determine whether it is an array?. 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