下列PHP函数描述错误的是
<?php /** * 数组排序和计算个数 */ function sortsAndCounts() { // asort - 对数组进行升序排序并保持索引关系 $fruits = array("d" => "lemon", "a" => "orange", "b" => "banana", "c" => "apple"); asort($fruits); foreach ($fruits as $key => $val) { echo "$key = $val\n"; } /* * 输出结果为: * c = apple b = banana d = lemon a = orange */ // sort — 对数组进行升序排序,此函数为 array 中的元素赋与新的键名。这将删除原有的键名,而不是仅仅将键名重新排序。 $fruits = array("1" => "lemon", "2" => "orange", "5" => "banana", "4" => "apple"); sort($fruits); foreach ($fruits as $key => $val) { echo "fruits[" . $key . "] = " . $val . "\n"; } /* * fruits[0] = apple fruits[1] = banana fruits[2] = lemon fruits[3] = orange */ // rsort — 对数组逆向排序,此函数为 array 中的元素赋与新的键名。这将删除原有的键名,而不是仅仅将键名重新排序。 $fruits = array("6"=>"lemon", "5"=>"orange", "strs"=>"banana", "ab"=>"apple"); rsort($fruits); foreach ($fruits as $key => $val) { echo "$key = $val\n"; } /* * 0 = orange 1 = lemon 2 = banana 3 = apple */ /** * count — 计算数组中的单元数目,或对象中的属性个数 * count ( mixed $array_or_countable [, int $mode = COUNT_NORMAL ] ) : int * array_or_countable 数组或者 Countable 对象。 * mode 如果可选的 mode 参数设为 COUNT_RECURSIVE(或 1),count() 将递归地对数组计数。对计算***数组的所有单元尤其有用。 * 返回 array_or_countable 中的单元数目。 如果参数既不是数组,也不是实现 Countable 接口的对象,将返回 1。 有个例外:如果 array_or_countable 是 NULL 则结果是 0。 */ $a[0] = 1; $a[1] = 3; $a[2] = 5; var_dump(count($a)); // 输出 int(3) $b[0] = 7; $b[5] = 9; $b[10] = 11; var_dump(count($b)); // 输出 int(3) var_dump(count(null)); // 输出 int(0) var_dump(count(false)); // 输出 int(1) } sortsAndCounts();
$age=array("Peter"=>"35","Ben"=>"37","Joe"=>"43");
asort($age);
?>
Key=Ben, Value=37
Key=Joe, Value=43