I'm converting XML file into associative array to pull out the data, the problem is that I have to make 10 loops depends on arrays number in order to get the data.
is there a better way to get a specific column data without creating many loops? because I want to assign them to variables.
the array I'm trying to get data from
Array
(
[catalog] => Array
(
[book] => Array
(
[0] => Array
(
[took] => Array
(
[dodo] => Array
(
[ahmadz] => Array
(
[lolo] => Array
(
[author] => Ralls, Kim
[title] => Midnight Rain
[genre] => Fantasy
[price] => 5.95
[publish_date] => 2000-12-16
[description] => A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.
)
)
)
)
)
[1] => Array
(
[took] => Array
(
[dodo] => Array
(
[ahmadz] => Array
(
[lolo] => Array
(
[author] => Ralls, Kim
[title] => Midnight Rain
[genre] => Fantasy
[price] => 5.95
[publish_date] => 2000-12-16
[description] => A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.
)
)
)
)
)
)
)
)
I removed all other data to make it easier to read, but there are many other values in the array. Anyway, how can I get the value of author for example.
echo $array['author'];
assuming that I have many author data, not one as the example above
Please help!.
Edited.....................
Array
(
[catalog] => Array
(
[book] => Array
(
[0] => Array
(
[took] => Array
(
[dodo] => Array
(
[ahmadz] => Array
(
[lolo] => Array
(
[tata] => Array
(
[author] => jac1
[title] => Midnight Rain1
[genre] => Fantasy
[price] => 5.95
[publish_date] => 2000-12-16
[description] => A former architect battles corporate zombies.
)
[tata2] => Array
(
[author] => jack2
[title] => Midnight Rain1
[genre] => Fantasy
[price] => 5.95
[publish_date] => 2000-12-16
[description] => A former architect battles corporate zombies.
)
)
)
)
)
)
[1] => Array
(
[took] => Array
(
[dodo] => Array
(
[ahmadz] => Array
(
[lolo] => Array
(
[tata] => Array
(
[author] => jack3
[title] => Midnight Rain1
[genre] => Fantasy
[price] => 5.95
[publish_date] => 2000-12-16
[description] => A former architect battles corporate zombies.
)
[tata2] => Array
(
[author] => jack4
[title] => Midnight Rain1
[genre] => Fantasy
[price] => 5.95
[publish_date] => 2000-12-16
[description] => A former architect battles corporate zombies.
)
)
)
)
)
)
)
)
)
As you see above I just want to get the value that has parent keys tata not tata2
so I can insert them separately into the database
$array['catalog']['book']['took']['dodo']['ahmadz']['lolo']['author'], without any loops. Maybe you simplified the array so much that the problem is not obvious and it would help to show at least a part of the unmodified input array.