On Friday 20 November 2009 11:12:29 pm Alban wrote:

> This is not a big problem but if a solution exists, this would be so
> cool ! Especialy when we have to check existance of twenty or more key in
> array. Code would be be lighter and clear.

I cannot comment on the rest of your post right now, but if you are checking 
for the existence of a bunch of keys in an associative array and setting 
defaults if they are not set, the following will be considerably faster and 
easier to read:

$my_array += array(
  'a' => 'A',
  'b' => 'B',
  'c' => 'C',
);

That will set $my_array['a'] to A iff it doesn't exist, ['b'] to B iff it 
doesn't exist, etc.  That is far nicer to read than a bunch of ternaries, 
short-circuited or no.  You can even stick the defaults array into a function 
and call it from various places to ensure your array always has the same sane 
defaults.

-- 
Larry Garfield
la...@garfieldtech.com

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to