note 106244 added to function.array-splice
| From: | mrsohailkhan at gmail dot com | Date: | Fri, 21 Oct 2011 07:34:49 +0000 |
| Subject: | note 106244 added to function.array-splice | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-184039@lists.php.net to get a copy of this message | ||
array_splice, split an array into 2 arrays. The returned arrays is the 2nd argument actually and the
used array e.g $input here contains the 1st argument of array, e.g
$input = array("red", "green", "blue", "yellow");
print_r(array_splice($input, 3)); // Array ( [0] => yellow )
print_r($input); //Array ( [0] => red [1] => green [2] => blue )
if you want to replace any array value do simple like that,
first search the array index you want to replace
$index = array_search('green', $input);// index = 1
and then use it as according to the definition
array_splice($input, $index, 1, array('mygreeen')); //Array ( [0] => red [1] =>
mygreeen [2] => blue [3] => yellow )
so here green is replaced by mygreen.
here 1 in array_splice above represent the number of items to be replaced. so here start at index
'1' and replaced only one item which is 'green'
----
Server IP: 69.147.83.197
Probable Submitter: 203.99.176.97
----
Manual Page -- http://www.php.net/manual/en/function.array-splice.php
Edit -- https://master.php.net/note/edit/106244
Del: integrated -- https://master.php.net/note/delete/106244/integrated
Del: useless -- https://master.php.net/note/delete/106244/useless
Del: bad code -- https://master.php.net/note/delete/106244/bad+code
Del: spam -- https://master.php.net/note/delete/106244/spam
Del: non-english -- https://master.php.net/note/delete/106244/non-english
Del: in docs -- https://master.php.net/note/delete/106244/in+docs
Del: other reasons-- https://master.php.net/note/delete/106244
Reject -- https://master.php.net/note/reject/106244
Search -- https://master.php.net/manage/user-notes.php