My question has to do with whether or not the syntax I am suing is "valid" php syntax, i.e. is it standard practice? will it be supported in future versions of php?
I am using php 5.3.8.
Given this test code below, is the reference to $a['elt2'] valid in the <input> tag value="$a[elt"]>? That is, no quotes around the key, elt1.
<?php
$a = array();
$a['elt1'] = "value of elt1";
$a['elt2'] = "value of elt2";
echo "a['elt'] = ", $a['elt1'], ". This is the usual way to reference the value, i.e key in quotes. <br />";
echo <<<PRINT_INPUT
<input type="text" size="150" name="demo"
value="a['elt2'] = $a[elt2]. Is this way of referencing the value ok, i.e. no quotes around the key?" />
PRINT_INPUT;
?>
Correction: That question should read:
Given this test code below, is the reference to $a['elt2'] valid in the <input> tag value="$a[elt1]">? That is, no quotes around the key, elt1.
Another correction:
Given this test code below, is the reference to $a['elt1'] valid in the <input> tag value="$a[elt1]">? That is, no quotes around the key, elt1.
Note that for the parser to correctly deal with a quoted array key (which is a good practice for consistency's sake), you cannot just use it as such within a double-quoted string. You will either have to use "complex" notation...
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks