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

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

Reply via email to