I have a HTML form where I will be sending all the information to the server side. One of my field is like
<option value="bus_info[{$k->bus_id},{$k->route_from},{$k->route_to}]">{$k->route_from} To {$k->route_to},{$k->bus_time}</option>
And when check in PHP side
$bus_information[] = $_REQUEST['bid'];
var_dump($bus_information);`
it shows the following result :
array
0 => string 'bus_info[1,Guwahati,Amguri]' (length=27)
Now how can I retrieve the elements from the array ? I tried echo $bus_information[0][0]; but it shows the result b ! Why so
Multidimensional arrays don’t work that way in HTML and PHP. You should use this in your form:
EDIT based on comment:
Sorry, this will not work at all. I’m assuming you want the user to select some sort of route, and based on that you want to pass a particular value. The way a
<select>works is this:In your HTML use this:
Now, in PHP you can access the value that was submitted like this:
You can use Arrays in the names of the input fields, so it would be possible to do something like this in HTML:
Note that I used the array notation on the
nameattribute, not the value. Now you can do this in PHP:So what you’re doing, using arrays in the
valueattribute will not work. You could do something like this:And then in PHP: