Re: RFC - Array slice syntactic sugar
| From: | Stanislav Malyshev | Date: | Fri, 20 Mar 2015 22:12:09 +0000 |
| Subject: | Re: RFC - Array slice syntactic sugar | ||
| References: | 1 2 3 4 5 6 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-85343@lists.php.net to get a copy of this message | ||
Hi!
> To be the same, your example would have to be:
>
> // alternative old
> foreach(array_slice($results, 0, 9, true) as $result) {
> echo $result . "\n"; // 1 2 3 4 5 6 7 8 9
> }
>
> since this will preserve the array keys.
You're not using the keys in foreach, so why you need to preserve them?
> $array[*1:4] = [1,2,3,4]; // Sets array items 1 through 4 to be the
> values (and keys if provided), of the array assigned.
This may be not so easy to implement - imagine passing $array[*1:4] by
reference. You should be able to do so, since $array[*1:4] is an lvalue
for you, but what would you pass? What if $array changes in the
meantime? There's a big can of worms here. And you already have
array_splice which doesn't have these issues.
--
Stas Malyshev
smalyshev@gmail.com