What Is The Right Way Of Usig " And ' Inside Sub-arrays In Php And Html?
Which of the following ways is the right one in using the characters ' and ' inside PHP's sub-arrays? #1 Way in debugging PHP code $_POST['login['username']']; #2 My original way
Solution 1:
You don't need to quote the array keys in HTML, this is correct:
<input name="login[password]"type="password" cols="92" />
This will create in $_POST a key 'login' whose value is another array having the key 'password', so you can access it like:
$_POST['login']['password']
Solution 2:
First of all, the correct form in html is what you have for #22 (no quotes).
Secondly, the entire point of doing this is because it will convert it into an array. When this form is posted, an array is created INSIDE of $_POST called login. To access it, try this:
echo$_POST['login']['username']; //echos username
echo$_POST['login']['password']; //echos password
Here's a quick overview of how the nesting looks:
'_POST' =>
array'login' =>
array'username' => string'myusername' (length=10)
'password' => string'mysecretpassword' (length=16)
Try doing this to get a good idea of what's going on and get output like above:
echo"<pre>";
var_dump($_POST);
echo"</pre>";
You'll be able to see all the nesting.
Solution 3:
just give your variables normal names: username
, password
and email
. you're creating your own problem.
Post a Comment for "What Is The Right Way Of Usig " And ' Inside Sub-arrays In Php And Html?"