You could skirt the issue entirely, and point out that efficiency is
over-rated. :) Why is faster equated with better?
Substr and strpos are common to most C-style languages so more people
are going to find the first example easier to maintain. Array_shift and
explode are both PHP-specific afaik. I expect most people are familiar
with the array shifting feature of array_shift, and less so with the
returns-the-first-element feature (/I/ needed to look it up, anyway...)
I don't understand why you would use array_shift to get the first
element of an array when you can just go array[0]? Is this not valid
PHP: explode('#', $innerRow['PeopEmail'])[0]? (genuine question)
Don't forgot the semi-colons ;)
Rimu
On 14/05/10 22:46, yeosteve wrote:
Thanks,
I've got a couple of students who are competing with each and me to
write the most efficient calls, and I'm anticipating their fisrt
question on Monday. Bit sad at this time on a Friday night .....
On May 14, 10:41 pm, Simon J Welsh<[email protected]> wrote:
You could also use list($address) = explode('#', $innerRow
['PeopEmail']), which does the same thing as array_shift, but without
an extra function call.
No matter what you pick, it'll be either two inbuilt function calls or
a language construct and an inbuilt function call, so you'll probably
need a heck of a lot of iterations before you'll notice one being
marginally faster than another.
As for each one is better, that's totally a matter of taste.
On 14/05/2010, at 10:33 PM, yeosteve wrote:
Hi
I have a field in a database with
[email protected]#mailto:[email protected]# . I want to reduce it
to just the email address.
Is is better/faster to use
substr($innerRow['PeopEmail'],0,strpos($innerRow['PeopEmail'],'#'))
or
array_shift(explode('#',$innerRow['PeopEmail']))
Thanks
Steve
---
Simon Welsh
Admin ofhttp://simon.geek.nz/
Who said Microsoft never created a bug-free program? The blue screen
never, ever crashes!
http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e
--
NZ PHP Users Group:http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
--
Phone (04) 381 4827 or 021 823 129
Skype rimu123
Web http://rimu.geek.nz/
--
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]