PHP
·
发表于 5年以前
·
阅读量:8296
phpɾ³ýÊý×eÖ¸¶¨ÔªËØʵÏÖ´uÂe
ÔÚPHPÖÐɾ³ýÊý×eÖ¸¶¨ÔªËصĺ¯ÊýûÓÐÖ±½ÓÄÜʹÓõģ¬¶aÊýÖ»ÄÜa×°½*¨
ÀýÈçarray_slice() º¯ÊýÔÚÊý×eÖиu¾ÝÌo¼þÈ¡³oÒ»¶ÎÖµ£¬²¢*µ»Ø.
array_slice(array,offset,length,preserve)
array£ºÊý×e
offset£º ¹ae¶¨È¡³oÔªËصĿªÊ¼Î»Öá£Èç¹uÊÇÕýÊý£¬Ôo´ÓÇ°Íuºo¿ªÊ¼È¡£¬Èç¹uÊǸºÖµ£¬´ÓºoÏoÇ°È¡ offset ¾ø¶ÔÖµ¡£
<?php
$a=array(0=>"Dog",1=>"Cat",2=>"Horse",3=>"Bird");
print_r(array_slice($a,1,2));
?>
Êa³o
Array ( [0] => Cat [1] => Horse )
»¹ÓÐarray_shift() º¯Êýɾ³ýÊý×eÖеĵÚÒ»¸oÔªËØ£¬²¢*µ»Ø±»É¾³ýÔªËصÄÖµ.
Ïa¶ÔµÄarray_pop() º¯Êýɾ³ýÊý×eÖеÄ×iºoÒ»¸oÔªËØ.
¼¸¸oº¯ÊýÓÃÏÂÀ´¾oµÃarray_search()±È½ÏʵÓÃarray_search() º¯ÊýÓe in_array() Ò»Ñu£¬ÔÚÊý×eÖвeÕÒÒ»¸o¼uÖµ¡£Èç¹uÕÒµ½Á˸ÃÖµ£¬Æ¥ÅaÔªËصļuÃu»a±»µ»Ø¡£Èç¹uûÕÒµ½£¬Ôoµ»Ø false
$array = array('1', '2', '3', '4', '5');
$del_value = 3;
unset($array[array_search($del_value , $array)]);//ÀuÓÃunsetɾ³ýÕa¸oÔªËØ
print_r($array);
Êa³o
array('1', '2', '4', '5');
¸ÐлÔĶÁ£¬Ï£ÍuÄÜ°iÖuµ½´o¼Ò£¬Ð»Ð»´o¼Ò¶Ô±¾Õ¾µÄÖ§³Ö£¡