Home >Backend Development >PHP Tutorial >php »ñÈ¡ Êý×éÖµ Êý×éµßµ¹ ¼üÃû²Ù×÷ʵÀý_PHP tutorial

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

WBOY
WBOYOriginal
2016-07-20 11:01:59893browse

ÏÂÃæ¾ÙÁ˼¸¸öʵÀýÖ÷ÒªÊǽ²¹ØÓÚÊä³öÊý×éËùÓеÄÖµ 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)


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/445392.htmlTechArticleÏÂÃæ¾ÙÁ˼¸¸öʵÀýÖ÷ÒªÊǽ²¹ØÓÚÊä³öÊý×éËùÓеÄÖµ array_values ,Ñ­»·Êä³öÊý×éµÄ¼ü/Öµ¶Ô²¢Òƶ¯Ö¸Õë reset,½«Êý×é...
Statement:
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