ID: 40792
User updated by: t dot kloppenburg at billiton dot de
Reported By: t dot kloppenburg at billiton dot de
Status: Open
Bug Type: Feature/Change Request
Operating System: Linux
PHP Version: 5.2.1
New Comment:
ok, I code in PHP all this years and I miss it in PHP :)
Previous Comments:
------------------------------------------------------------------------
[2007-03-13 11:23:03] t dot kloppenburg at billiton dot de
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 this bug report at http://bugs.php.net/?id=40792&edit=1