note 101450 modified in function.array-pop by danbrown
| From: | danbrown@php.net | Date: | Fri, 17 Dec 2010 02:40:49 +0000 |
| Subject: | note 101450 modified in function.array-pop by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175013@lists.php.net to get a copy of this message | ||
to apply arra_pop serveral times but not recursive
<?php
function array_mpop($array, $iterate)
{
if(!is_array($array) && is_int($iterate))
return false;
while(($iterate--)!=false)
array_pop($array);
return $array;
}
?>
for test :
<?php
$a = array("titi", "toto", "tata", "tonton",
"toutou", "tutu");
$a = array_mpop($a, 2);
var_dump($a);
?>
result :
array(4) { [0]=> string(4) "titi" [1]=> string(4) "toto" [2]=>
string(4) "tata" [3]=> string(6) "tonton" }
--was--
to apply arra_pop serveral times but not recursive
function array_mpop($array, $iterate)
{
if(!is_array($array) && is_int($iterate))
return false;
while(($iterate--)!=false)
array_pop($array);
return $array;
}
for test :
$a = array("titi", "toto", "tata", "tonton",
"toutou", "tutu");
$a = array_mpop($a, 2);
var_dump($a);
result :
array(4) { [0]=> string(4) "titi" [1]=> string(4) "toto" [2]=>
string(4) "tata" [3]=> string(6) "tonton" }
http://php.net/manual/en/function.array-pop.php