array_splice() RFD
| From: | Andrey Zmievski | Date: | Fri, 16 Jul 1999 19:28:03 +0000 |
| Subject: | array_splice() RFD | ||
| Groups: | php.version4 | ||
| Request: | Send a blank email to php-version4+get-2127@lists.php.net to get a copy of this message | ||
Have a bit of a conceptual problem with array_splice here, and wanted to get
feedback from y'all.
Right now the way array_splice works is like this:
$input = array(1, 2, 3, 4);
$removed = array_splice($input, 1, 2, "a", "b");
This would result in $input being array(1, "a", "b", 4). So it basically
takes a variable number of arguments and replaces the removed values with
them.
Now, what if instead of calling a function and passing each new element to it
as a parameter you wanted to pass an array of these elements since you don't
know how many you will have at run time. Something like:
$input = array(1, 2, 3, 4);
$repl = array("d", "e", "f");
$removed = array_splice($input, 1, 2, $repl);
And $input would be array(1, "d", "e", "f", 4).
Which way is more convenient? I'd vote for the second one since it gives you
more flexibility. It's just that if you wanted to replace the removed values
with an actual array you'd need to do array_splice($input, 1, 2,
array($repl)).
I'd like to hear your thoughts on this one,
-Andrey
* Black holes are where God divided by zero. *