Re: [PATCH] array_get()

From: Date: Tue, 11 Sep 2007 02:31:05 +0000
Subject: Re: [PATCH] array_get()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-32227@lists.php.net to get a copy of this message
On 11.09.2007 02:12, Andrew Shearer wrote: > Here's a patch against HEAD that implements the array_get function > previously suggested on this list. I also attached a test suite, > which should go in ext/standard/tests/array/array_get.phpt. Feedback > is welcome. > > Independently, someone else had posted the same idea as a feature > request for PHP 5, and if there's interest I can backport it. > > 40792 Open Wish: Function array_get(&$mixed, $key, $defaultvalue) > > /* Prototype: > * mixed array_get ( array $search, mixed $key, mixed $default ); > * Description: > * Returns the value corresponding to the given key if the key exists > * in the array. $key can be any value possible for an array index. > * If the key does not exist, the function returns $default, or FALSE > * if $default is not specified. Also works on objects. > * Similar semantics to array_key_exists. > */ Can you explain, what's the difference between your implementation and this? <?php function array_get(&$array, $key, $default) { if (isset($array[$key])) { return $array[$key]; } return $default; } ?> -- Wbr, Antony Dovgal

« previous php.internals (#32227) next »