im trying to loop through my array, without success though..
Array
(
[Aircraft] => Array
(
[0] => Array
(
[A] => Gulfstream G100
[B] => Cessna Citation Excel
[C] => Cessna 208
[D] => Piper Aztec
[E] => Embraer ERJ 145
[F] => Airbus A330
[G] => Boeing Business Jet
)
[1] => Array
(
[A] => Cessna Citation CJ3
[B] => Dassault Falcon 900
[C] => Gulfstream G300
[D] => Boeing 767
[E] => ATR 42
[F] => Gulfstream IV
[G] => Airbus A320
)
)
)
i have tried almost everything i can think of so far..
even..
print $data[0][A];
.. wount work.
My plan is to loop (foreach?) through this array..
please help me..
foreach($array['Aircraft'] as $array){
echo $array['A'];
}
Have you tried something like this?
We need to see some code where you've tried to iterate through the array. You should be trying something like $data['aircraft'][0][A]
to access a single item's value.
Something like this should work to loop through:
foreach ($array AS $aircraft) {
echo $aircraft[A] . PHP_EOL;
}
// Gulfstream G100
// Cessna Citation CJ3
Hopefully enough to give you an idea.
Very easy way : use var_dump()
or print_r()
functions to dump variable in php
But, for a specific needs, you have to think with recursive approach
function loopRecursive($input) {
foreach ($input as $key => $value ) {
if (is_array($value)) {
loopRecursive($value);
}
else {
printf('Key: %s value: %s<br /> ',$key, $value);
}
}
}
Try this:
foreach($array['Aircraft'] as $array){
echo $array['A']." "; // Will print Gulfstream G100 Cessna Citation CJ3
}
Hope this helps.
Peace! xD