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

php »ñÈ¡Êý×éÖµ Êý×éµßµ¹ ¼üÃû²Ù×÷ʵÀý

WBOY
Release: 2016-06-13 11:18:25
Original
1068 people have browsed it

ÏÂÃæ¾ÙÁ˼¸¸öʵÀýÖ÷ÒªÊǽ²¹ØÓÚÊä³öÊý×éËùÓеÄÖµ array_values ,Ñ­»·Êä³öÊý×éµÄ¼ü/Öµ¶Ô²¢Òƶ¯Ö¸Õë reset,½«Êý×éµßµ¹£¬²»±£Áô¼üÃûarray_reverseº¯Êý²Ù×÷¡£  

ÏÂÃæ¾ÙÁ˼¸¸öʵÀýÖ÷ÒªÊǽ²¹ØÓÚÊä³öÊý×éËùÓеÄÖµ array_values ,Ñ­»·Êä³öÊý×éµÄ¼ü/Öµ¶Ô²¢Òƶ¯Ö¸Õë reset,½«Êý×éµßµ¹£¬²»±£Áô¼üÃûarray_reverseº¯Êý²Ù×÷¡£
*/

$array=array("size"=>"xl","color"=>"gold");   //¶¨ÒåÒ»¸öÊý×é
print_r(array_values($array));      //Êä³öÊý×éËùÓеÄÖµ

/*
¶¨ÒåºÍÓ÷¨
array_values() º¯Êý·µ»ØÒ»¸ö°üº¬¸ø¶¨Êý×éÖÐËùÓмüÖµµÄÊý×飬µ«²»±£Áô¼üÃû¡£

Óï·¨
array_values(array)
*/

$fruit=array('a'=>'apple','b'=>'banana','c'=>'cranberry'); //¶¨ÒåÒ»¸öÊý×é
reset($fruit);         //Ö¸ÕëÒƶ¯µÚÒ»¸öλÖÃ
while(list($key,$val)=each($fruit))     //Ñ­»·Êä³öÊý×éµÄ¼ü/Öµ¶Ô²¢Òƶ¯Ö¸Õë
{
  echo "$key=>$valn";       //Êä³öÊý×éµÄ¼ü¼°Öµ
}

/*

*/

$input=array("php½Ì³Ì",3.0,array("green","red"));    //¶¨ÒåÒ»¸öÊý×é
$result=array_reverse($input);       //½«Êý×éµßµ¹£¬²»±£Áô¼üÃû
$result_keyed=array_reverse($input,true);    //½«Êý×éµßµ¹£¬±£Áô¼üÃû
print_r($result);          //ÏÔʾµÚÒ»ÖÖ½á¹û
print_r($result_keyed);        //ÏÔʾµÚ¶þÖÖ½á¹û

/*
¶¨ÒåºÍÓ÷¨
array_reverse() º¯Êý½«Ô­Êý×éÖеÄÔªËØ˳Ðò·­×ª£¬´´½¨ÐµÄÊý×é²¢·µ»Ø¡£Èç¹ûµÚ¶þ¸ö²ÎÊýÖ¸¶¨Îª true£¬ÔòÔªËصļüÃû±£³Ö²»±ä£¬·ñÔò¼üÃû½«¶ªÊ§¡£

Óï·¨
array_reverse(array,preserve)
*/

$array=array(0=>100,"color"=>"red");      //¶¨ÒåÒ»¸öÊý×é
print_r(array_keys($array));        //·µ»Ø¸ÃÊý×éµÄËùÓмüÃû
$array=array("blue","red","green","blue","blue");     //¶¨ÒåÒ»¸öÊý×é
print_r(array_keys($array,"blue"));       //·µ»ØֵΪblueµÄ¼üÃû
//¶¨ÒåÒ»¸öÔªËØΪÊý×éµÄÊý×é
$array=array("color"=>array("blue","red","green"),"size"=>array("small","medium","large"));
print_r(array_keys($array));        //·µ»ØÊý×éµÄËùÓмüÃû

/*
¶¨ÒåºÍÓ÷¨
array_keys() º¯Êý·µ»Ø°üº¬Êý×éÖÐËùÓмüÃûµÄÒ»¸öÐÂÊý×é¡£

Èç¹ûÌṩÁ˵ڶþ¸ö²ÎÊý£¬ÔòÖ»·µ»Ø¼üֵΪ¸ÃÖµµÄ¼üÃû¡£

Èç¹û strict ²ÎÊýÖ¸¶¨Îª true£¬Ôò php »áʹÓÃÈ«µÈ±È½Ï (===) À´Ñϸñ¼ì²é¼üÖµµÄÊý¾ÝÀàÐÍ¡£

Óï·¨
array_keys(array,value)


Related labels:
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