php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52425 array_shift/array_pop: add parameter that tells how many to elements to pop
Submitted: 2010-07-24 08:07 UTC Modified: 2010-07-24 17:40 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: planet36 at gmail dot com Assigned:
Status: Wont fix Package: Unknown/Other Function
PHP Version: 5.3.3 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: planet36 at gmail dot com
New email:
PHP Version: OS:

 

 [2010-07-24 08:07 UTC] 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
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-24 17:40 UTC] dtajchreber@php.net
-Status: Open +Status: Wont fix
 [2010-07-24 17:40 UTC] dtajchreber@php.net
array_splice()
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 12 02:01:27 2025 UTC