Why does the following code:
if (isset($_GET['trainType']) && isset($_GET['onTime']) && isset($_GET['gotSeat'])) {
$train[0]['trainType'] = $_GET['trainType'];
$train[0]['trainType']['onTime'] = $_GET['onTime'];
$train[0]['trainType']['gotSeat'] = $_GET['gotSeat'];
echo '<pre>';
print_r($train);
echo '</pre>';
}
Return the following array:
Array
(
[0] => Array
(
[trainType] => tLine
)
)
I had initially assumed it would return something more resembling to this:
Array
(
[0] => Array
(
[trainType] => 'passenger'
Array =>
(
[onTime] => true
[gotSeat] => true
)
)
)
Any guidance on what I should do to achieve what I am trying to do? I am hoping that my code makes what I am trying to do obvious.
This line will set
trainTypeto a string value:Then these lines will actually be used for character substitution, with a slight twist:
Both
onTimeandgotSeatwill result in0(because you’re working with a string) and will replace the first character withfthenb.Therefore
print_r($train)returns:Here is how I would format this data:
The result of
print_r($trains):Accessing this data: