Date: 09/04/01
- Next message: Sebastian Bergmann: "Re: [PHP-DEV] Re: base_convert() broken"
- Previous message: mail <email protected>: "[PHP-DEV] Bug #13123: UploadProblems"
- In reply to: Anders Johannsen: "[PHP-DEV] Range literal (proposal)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
flagzenNO-SPAM <email protected>
--------------------------
Anders Johannsen <anders <email protected>> wrote in message
20010904044000.40019.qmail <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: php-dev-unsubscribe <email protected> For additional commands, e-mail: php-dev-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Sebastian Bergmann: "Re: [PHP-DEV] Re: base_convert() broken"
- Previous message: mail <email protected>: "[PHP-DEV] Bug #13123: UploadProblems"
- In reply to: Anders Johannsen: "[PHP-DEV] Range literal (proposal)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

