From:             t dot kloppenburg at billiton dot de
Operating system: Linux
PHP version:      5.2.1
PHP Bug Type:     Feature/Change Request
Bug description:  Wish: Function array_get(&$mixed, $key, $defaultvalue)

Description:
------------
I miss a function or ArrayObject method to get an element of an array, or
alternativly a default value if the key is not set in the array.

In python:
  mydict = {'key1' : 'value1'}
  val = mydict.get('otherkey', 'defaultvalue')
  -> 'defaultvalue'

This is very handy when dealing with arrays.

I'ld be happy to see this in PHP4 and PHP5. It could look like this:

  $cfg = array('version' => '1.2v', 'othercfg' => 'otherval');
  $tmppath = array_get( $cfg, 'tmppath', '/tmp' );
  -> '/tmp'

or with ArrayObject as:
  $tmppath = $arrobj->get( 'tmppath', '/tmp' );
  -> '/tmp'  (if not set in the array)

I code in Python since 6 or 7 years, and I really miss this function in
everyday-use.



-- 
Edit bug report at http://bugs.php.net/?id=40792&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=40792&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=40792&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=40792&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=40792&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=40792&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=40792&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=40792&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=40792&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=40792&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=40792&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=40792&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=40792&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=40792&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=40792&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=40792&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=40792&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=40792&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=40792&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=40792&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=40792&r=mysqlcfg

Reply via email to