note 81462 modified in function.array-splice by thiago

From: Date: Thu, 24 Jul 2008 17:24:54 +0000
Subject: note 81462 modified in function.array-splice by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142674@lists.php.net to get a copy of this message
array_splice($input, -1) / array_slice($input, 1) equivalent to array_shift($input) ????? Try this: <?php $input = array('key1' => array('deep1' => 'Value'), 'key2' => array('deep2' => 'Value'), 'key3' => array('deep3' => 'Value')); $foo_splice = array_splice($input, -1); $foo_shift = array_shift($input); echo "<pre>".print_r($foo_splice, true)."</pre>"; echo "<pre>".print_r($foo_shift, true)."</pre>"; ?> Output: Array ( [key3] => Array ( [deep3] => Value ) ) Array ( [deep1] => Value ) --was-- array_splice($input, -1) / array_slice($input, 1) equivalent to array_shift($input) ????? Try this: $input = array('key1' => array('deep1' => 'Value'), 'key2' => array('deep2' => 'Value'), 'key3' => array('deep3' => 'Value')); $foo_splice = array_splice($input, -1); $foo_shift = array_shift($input); echo "<pre>".print_r($foo_splice, true)."</pre>"; echo "<pre>".print_r($foo_shift, true)."</pre>"; Output: Array ( [key3] => Array ( [deep3] => Value ) ) Array ( [deep1] => Value ) http://php.net/manual/en/function.array-splice.php

« previous php.notes (#142674) next »