Mutidimentional Array Not parsing in html text field

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
maingroup
Forum Newbie
Posts: 12
Joined: Thu Apr 24, 2008 2:04 pm

Mutidimentional Array Not parsing in html text field

Post 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.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: Mutidimentional Array Not parsing in html text field

Post 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]}>";
JustPHP
Forum Newbie
Posts: 2
Joined: Thu Apr 24, 2008 3:22 pm

Re: Mutidimentional Array Not parsing in html text field

Post 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";
Post Reply