Edit report at http://bugs.php.net/bug.php?id=52425&edit=1

 ID:               52425
 Updated by:       [email protected]
 Reported by:      planet36 at gmail dot com
 Summary:          array_shift/array_pop: add parameter that tells how
                   many to elements to pop
-Status:           Open
+Status:           Wont fix
 Type:             Feature/Change Request
 Package:          Unknown/Other Function
 Operating System: Linux
 PHP Version:      5.3.3

 New Comment:

array_splice()


Previous Comments:
------------------------------------------------------------------------
[2010-07-24 08:07:26] planet36 at gmail dot com

Description:
------------
Description:

It would be nice if functions array_pop and array_shift took a parameter
that told how many elements to pop.



Example:

mixed array_pop ( array &$array , $num = 1 )

mixed array_shift ( array &$array , $num = 1 )

Test script:
---------------
function array_pop_mine(array &$array, $num)

{

        $removed = array();

        while ($num > 0)

        {

                //$removed[] = array_pop($array);

                array_unshift($removed, array_pop($array));

                --$num;

        }

        //return array_reverse($removed);

        return $removed;

}

$arr = array(3, 1, 4, 1, 5, 9);

print_r($arr);

$rem = array_pop_mine($arr, 3);

print_r($arr);

print_r($rem);

Actual result:
--------------
Array

(

    [0] => 3

    [1] => 1

    [2] => 4

    [3] => 1

    [4] => 5

    [5] => 9

)

Array

(

    [0] => 3

    [1] => 1

    [2] => 4

)

Array

(

    [0] => 1

    [1] => 5

    [2] => 9

)


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52425&edit=1

Reply via email to