“ rsort”功能可用于检查数组是否为多维。它采用一个参数,即需要检查的数组,并根据数组的性质返回是或否。
<?php
$my_array = array(
   array("This", "is", "a", "sample"),
   array("Hi", "there")
);
function multi_dim( $my_arr )
{
   rsort( $my_arr );
   return isset( $my_arr[0] ) && is_array( $my_arr[0] );
}
echo "Is the array multi-dimensional? ";
var_dump( multi_dim( $my_array ) );
?>输出结果
Is the array multi-dimensional? bool(true)
定义了一个包含字符串元素的数组。定义了一个名为“ multi_dim”的函数,该函数使用“ rsort”对数组的元素进行排序。然后,使用“ isset”功能对数组的元素执行“ AND”运算。这将有助于了解数组是一维还是多维。