note 107054 added to function.array-reverse
| From: | Laymain at osu1 dot php dot net | Date: | Tue, 03 Jan 2012 17:10:55 +0000 |
| Subject: | note 107054 added to function.array-reverse | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185274@lists.php.net to get a copy of this message | ||
<?php
function array_reverse_ref(array &$array, $preserve_keys = false)
{
$new_array = array();
for (end($array); ($key = key($array)) !== null; end($array))
{
$value = array_pop($array);
if ($preserve_keys) $new_array[$key] = $value;
else $new_array[] = $value;
}
$array = $new_array;
}
$test = array(
1 => 'first',
6 => 'mid',
3 => 'last',
);
array_reverse_ref($test, true);
var_dump($test);
/*
array(3) {
[3]=>
string(4) "last"
[6]=>
string(3) "mid"
[1]=>
string(5) "first"
}
*/
array_reverse_ref($test);
var_dump($test);
/*
array(3) {
[0]=>
string(5) "first"
[1]=>
string(3) "mid"
[2]=>
string(4) "last"
}
----
Server IP: 89.31.146.176
Probable Submitter: 85.169.35.130
----
Manual Page -- http://www.php.net/manual/en/function.array-reverse.php
Edit -- https://master.php.net/note/edit/107054
Del: integrated -- https://master.php.net/note/delete/107054/integrated
Del: useless -- https://master.php.net/note/delete/107054/useless
Del: bad code -- https://master.php.net/note/delete/107054/bad+code
Del: spam -- https://master.php.net/note/delete/107054/spam
Del: non-english -- https://master.php.net/note/delete/107054/non-english
Del: in docs -- https://master.php.net/note/delete/107054/in+docs
Del: other reasons-- https://master.php.net/note/delete/107054
Reject -- https://master.php.net/note/reject/107054
Search -- https://master.php.net/manage/user-notes.php