Page 1 of 1

Mutidimentional Array Not parsing in html text field

Posted: Thu Apr 24, 2008 2:10 pm
by maingroup
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hello,

Please take a look at the following codes

Code: Select all

<?php
$arr = array(0 => array(6 => 5, 13 => 9, "a" => 42));
echo $arr[0][6]; //gives 5
echo '<br>';
echo "<input type = text value= $arr[0][6]>"; //gives Array[6] in an Html input value field
?>
Why $arr[0][6] is not returning the proper result in the input field?

By the way, I have never run into any problems of parsing single dimentional array in input value field.


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Mutidimentional Array Not parsing in html text field

Posted: Thu Apr 24, 2008 2:41 pm
by Oren
How can PHP decide? did you mean the value of $arr[0][6]? or the value of $arr[0] followed by the string "[6]"?
Use {} like this to help PHP decide:

Code: Select all

echo "<input type = text value= {$arr[0][6]}>";

Re: Mutidimentional Array Not parsing in html text field

Posted: Thu Apr 24, 2008 3:28 pm
by JustPHP
Yes if you place array within strings you need to use complex notation. Or

Code: Select all

echo "start of string".$array[0][6]."end of string";