Array keys expected behaviour?

php.internals

Arjen Brouwer

23 years ago
Hi, Take the following code: <? $car = array( "brand" => "Porsche" ,"color" => black ); function nvl(&$var, $default = false) { return (isset($var)) ? $var : $default; } echo "Color: " . nvl($car["color"]) . "\n"; echo "Spoiler: " . nvl($car["spoiler"], "yes"); echo "\n\n"; print_r($car); ?> Output: --- Color: black Spoiler: yes Array ( [brand] => Porsche [color] => black [spoiler] => ) ---Look at the output of the last print_r, the key "spoiler" is defined? But is never defined in the code ...Just wondering, is this the expected behaviour?Running PHP4.3.2RC3Cheers, Arjen

David Grant

23 years ago
Arjen Brouwer wrote:
> ---Look at the output of the last print_r, the key "spoiler" is defined?
Look at the second note here: http://www.php.net/manual/en/language.references.whatdo.php
-- David Grant Web Developer david.grant@wiredmedia.co.uk http://www.wiredmedia.co.uk Tel: 0117 930 4365, Fax: 0870 169 7625 Wired Media Ltd Registered Office: 43 Royal Park, Bristol, BS8 3AN Studio: Whittakers House, 32 - 34 Hotwell Road, Bristol, BS8 4UD Company registration number: 4016744 ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. **********************************************************************