FW: Accessing a Char in an Array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



*Sorry Curt for sending this to you.*

Hi,

Well if any one is interested in the speed I set up an example that you
can go to.  Though, when I run the example substr() is very neurotic (or
it seems that it is to me). It can process the same line of code at a
lot of different intervals, while accessing it with {} is pretty
consistant.

What is the cause of this?

I thought it might be the server, but would that not effect it for both
tests (two others tests with objects)?

By the by, during my testing I found that using {} to access the first
char in a string was anywhere from .5 to 4 times faster.

Please let me know if I did the testing wrong, I don't believe I did but
I was at work when I did it.

http://dev.jepaonline.com/php/strings/substr/

Kind regards,

Justin Palmer


> -----Original Message-----
> From: Curt Zirzow [mailto:php-general@xxxxxxxxxxxxxxxxx]
> Sent: Monday, December 20, 2004 7:27 PM
> To: 'PHP General'
> Subject: Re:  Accessing a Char in an Array
> 
> 
> * Thus wrote Justin Palmer:
> > In an earlier thread labeled "first letter", it was suggested that
> > substr() be used.
> 
> Just for the record the usage of
> 
>   $str = 'a string';
>   $str[0];
> 
> Is strongly discouraged, it is recommended to use:
> 
>   $str{0};
> 
> See Section (String access and modification by character):
>   http://php.net/language.types.string
> 
> > 
> > >Check this out... http://us2.php.net/manual/en/function.substr.php.
> > 
> > So my question is:
> > 
> > What is faster using substr or accessing the string like an array?
> > 
> > I know I could test this myself, but I thought someone may
> have done
> > this already.
>  
> Speed is probably negligible. It probably comes down to readablity.
> 
> 
> Curt
> --
> Quoth the Raven, "Nevermore."
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux