Re: RFC - Array slice syntactic sugar

From: Date: Fri, 20 Mar 2015 13:04:36 +0000
Subject: Re: RFC - Array slice syntactic sugar
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-85283@lists.php.net to get a copy of this message
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]

« previous php.internals (#85283) next »