note 63847 added to language.types.array

From: Date: Sat, 01 Apr 2006 20:54:14 +0000
Subject: note 63847 added to language.types.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-107138@lists.php.net to get a copy of this message
Passing variables into the array constructor: Just a NOOB pointer, I couldn't find other examples for this. If you want to pass the value of an existing variable into the array() constructor, you can quote it or not, both methods are valid. <? $foo_value = 'foo string'; $bar_value = 'bar string'; $myArray = array( 'foo_key' => $foo_value, // not quoted 'bar_key' => "$bar_value"); // quoted foreach ($myArray as $k => $v) { echo "\$myArray[$k] => $v.<br />\n"; } ?> Both of these will work as expected, but the unqoted $foo_value method above is marginally faster because adding quotes adds an additional string de-reference. ---- Server IP: 216.194.113.175 Probable Submitter: 24.4.238.121 ---- X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER, HTML_MESSAGE autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/language.types.array.php Edit -- http://master.php.net/note/edit/63847 Del: integrated -- http://master.php.net/note/delete/63847/integrated Del: useless -- http://master.php.net/note/delete/63847/useless Del: bad code -- http://master.php.net/note/delete/63847/bad+code Del: spam -- http://master.php.net/note/delete/63847/spam Del: non-english -- http://master.php.net/note/delete/63847/non-english Del: in docs -- http://master.php.net/note/delete/63847/in+docs Del: other reasons-- http://master.php.net/note/delete/63847 Reject -- http://master.php.net/note/reject/63847 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#107138) next »