Maison > php教程 > php手册 > le corps du texte

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

WBOY
Libérer: 2016-06-13 10:28:07
original
1089 Les gens l'ont consulté

介绍几个 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
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!