Home > php教程 > php手册 > body text

介绍几个php4中非常有用的数组函数转载关联数组等同于PERL里的哈希数组。以前我一直以为PHP里没...

WBOY
Release: 2016-06-13 10:28:07
Original
1117 people have browsed it

介绍几个 php4 中非常有用的"数组"函数 1 void extract (array var_array [, int extract_type ][, string prefix]]) 把一个关联数组展开为变量名和变量的值,如果有冲突则由后面的参数指定处理方法! 如:
"blue", "size" => "medium", "shape" => "sphere"); extract ($var_array, EXTR_PREFIX_SAME, "wddx"); print "$color, $size, $shape, $wddx_sizen"; ?> 2 array compact (mixed varname [, mixed ...]) 和上面的函数相反,把变量名和变量的值保存到关联数组里面! 如: $city = "San Francisco"; $state = "CA"; $event = "SIGGRAPH"; $location_vars = array ("city", "state"); $result = compact ("event", "nothing_here", $location_vars); $result 结果为 array ("event" => "SIGGRAPH", "city" => "San Francisco", "state" => "CA"). 3 bool in_array (mixed needle, array haystack) 判断数组中是否有这个值 4 void natsort (array array) 以自然数的方法排序数组,这时 12 将排在2的后面 $array1 = $array2 = array ("img12.png","img10.png","img2.png","img1.png"); sort($array1); echo "标准排序n"; print_r($array1); natsort($array2); echo "n自然排序n"; print_r($array2); 代码输出为: 标准排序 Array ( [0] => img1.png [1] => img10.png [2] => img12.png [3] => img2.png ) 自然排序 Array ( [3] => img1.png [2] => img2.png [1] => img10.png [0] => img12.png )

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template