Alex Bowers wrote on 20/03/2015 12:32:
We also need to consider then the possibility of setting data by position.

What should $array[@1:3]  = [1,2,3] do?

Should it overwrite the values there, and append any that don't exist, or should it be a parse error?


Good catch. I guess it could delete the range and replace with the new value, regardless of size - then you could remove elements from an array with it, too:

$array[@1:3] = []; // Remove the second through fourth element
$array['x':'z'] = []; // Remove all elements with keys between 'x' and 'z', inclusive

Not sure how that compares to other languages with similar syntax.

It would be kind of cool if it applied to string subscripts as well:

$version = 'PHP 5.6.1';
$version{4:} = '7!';
echo $version; // 'PHP 7!'

Regards,
--
Rowan Collins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to