PHP - is_array() 函式



定義和用法

is_array() 函式用於檢查一個變數是否為陣列。

語法

bool is_array ( mixed $value )

引數

序號 引數及描述
1

被評估的變數

返回值

如果為陣列,則此函式返回布林值 true,否則返回 false

依賴項

PHP 4 及以上版本

示例

以下示例演示了 is_array() 函式的用法:

<?php
   $a = array('a', 'b', 'c');
   echo 'a '.(is_array($a) ? 'Is an Array'   : 'not an Array').'<br>';

   $b = array("a"=>"1", "b"=>"2", "c"=>"3");
   echo 'b '.(is_array($b) ? 'Is an Array'   : 'not an Array').'<br>';

   $c = 'this is a string';
   echo 'c is '.(is_array($c) ? 'Is an Array'   : 'not an Array').'<br>';
?>

輸出

這將產生以下結果:

a Is an Array
b Is an Array
c is not an Array
php_variable_handling_functions.htm
廣告