I think that also this is a good idea, it's similar to slice selection in
python (in python you write var[0:2] etc...)

--------------------------
Federico
[EMAIL PROTECTED]
--------------------------

Anders Johannsen <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]
> It would be nice addition to have a Range literal in PHP. The "range()"
> implements the functionality in part, but in an extremly ineffecient
> manner. What I would like to see, is a builtin Range 'type', which only
> holds the start and end points.
>
> Let's consider some practical applications:
>
> 1:
> $str = "this is a test string";
> $str[0...4] #=> "this"
>
> 2:
> $arr = ['this', 'is', 'a', 'test']
> $arr[2..4]  #=> ['is', 'a']
>
> 3:
> $str = "hello world";
> $offset = 6;
> $end     = 11;
>
> substr($str, $offset...$end);  #=> "world"
>
> 4:
> foreach ('a'..'d' as $chr) {
> print $chr;
> }
> # Prints a,b,c
>
> 5:
> $range = 5...10;
>
> range_first($range); #=> 5
> range_last($range); #=> 10
> range_size($range);    #=> 6
>
> 6:
> $range = range(0, 3);
>
> for ($i = 0; $i == $range; $++) {
> print $i;
> }
>
> # Prints 0, 1, 2, 3
>
> $i = 0;
> while ($i == $range) {
> print $i++;
> }
>
> # Prints 0, 1, 2, 3
>
> An implementation of my suggestion would obviously require some work
> (hacking?) inside the Zend Engine, which, I believe, is best left up to
> people with a understanding of its internals (which rules me out).
>
> Let me know what you think.
>
> Btw: Is there a PHP mechanism for language improvement suggestions (such
as
> Perl's RFC or Ruby's RCR)?
>
> /A
> --
> Anders Johannsen, Denmark



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to