php - Using citation marks around a variable in array access -
i'm reading som legacy code , come on curious case:
$my_assoc_array; /* user defined associative array */ $my_key; /* user defined string */ $value = $my_assoc_array["$my_key"];
is there clever reason why want have citation marks ("
) around variable when it's used key? special corner case? or there no reason @ this?
-- edit --
maybe in old version of php there difference? (remember legacy code).
there 1 example can find output differs when $mykey = false
. (which perhaps not apply example $mykey string, again: wild wild world of php)
<?php $arr = array("1"=>"b", "0"=>"a"); $mykey = false; var_dump($arr[$mykey]); // returns "a" var_dump($arr["$mykey"]); // gives undefined index error $mykey = true; var_dump($arr[$mykey]); // returns "b" var_dump($arr["$mykey"]); // returns "b"
what can (mis-)used beats me...
Comments
Post a Comment