note 107605 added to function.array-reverse

From: Date: Tue, 21 Feb 2012 13:41:44 +0000
Subject: note 107605 added to function.array-reverse
Groups: php.notes 
Request: Send a blank email to php-notes+get-186257@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: 88.191.78.34 ---- Manual Page -- http://www.php.net/manual/en/function.array-reverse.php Edit -- https://master.php.net/note/edit/107605 Del: integrated -- https://master.php.net/note/delete/107605/integrated Del: useless -- https://master.php.net/note/delete/107605/useless Del: bad code -- https://master.php.net/note/delete/107605/bad+code Del: spam -- https://master.php.net/note/delete/107605/spam Del: non-english -- https://master.php.net/note/delete/107605/non-english Del: in docs -- https://master.php.net/note/delete/107605/in+docs Del: other reasons-- https://master.php.net/note/delete/107605 Reject -- https://master.php.net/note/reject/107605 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#186257) next »