Re: Quick Poll: PHP 4 / 5

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

 



Stephen Leaf wrote:
So yes a bug. But for those that want to be able to grab only what we need. in my case array_pop's returned element. I don't wanna be hassled with the "are you sure you wanted to ignore part of what we did?" It's almost like every program asking "are you sure you wanted to close me?" everytime I get asked that I always think... "I did just click the X.. so.... Yah......."

But why use array_pop() to get the last element, when you know it's intended to shorten its passed array as well?

I mean, sure, it might take a few more lines of code to do it properly, but it has the advantage that whoever has to look at the code next might actually understand what's going on in your head.

$array = explode( ',', $some_string );
$last_element_pos = count( $array ) - 1;
$last_element = $array[$last_element_pos];

[ sure, you could put the count( $array ) - 1 as the array subscript but I was just extending it out for illustration... it's probably easier to understand later on anyway. ]

--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--
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