I have an array structure like so:
Array
(
[0] => Array
(
[term_id] => 22
[name] => Aaa Aa
[slug] => aaa-aa
[term_group] => 0
[term_taxonomy_id] => 22
[taxonomy] => category
[description] =>
[parent] => 13
[count] => 0
[cat_ID] => 22
[category_count] => 0
[category_description] =>
[cat_name] => Aaa Aa
[category_nicename] => aaa-aa
[category_parent] => 13
)
[1] => Array
(
[term_id] => 11
[name] => adasdasda
[slug] => adasdasda
[term_group] => 0
[term_taxonomy_id] => 11
[taxonomy] => category
[description] => asdsdad
[parent] => 1
[count] => 0
[cat_ID] => 11
[category_count] => 0
[category_description] => asdsdad
[cat_name] => adasdasda
[category_nicename] => adasdasda
[category_parent] => 1
)
)
I was wondering how to go about easily looping through the data for output…
For example, I want to display all the names, descriptions and slugs.
I can’t figure out how to display them all…
This is what I have, and it kind of works, however it’s throwing and invalid argument.
for ($i = 0; $i <= count($data); $i++) {
foreach($data[$i] as $key => $value){
echo "KEY: ".$key."<br />\n VALUE: ".$value."<br />\n";
}
}
No need to use the
forloop,foreachwill suffice. This way you won’t have to deal with the out of boundary (index not set) warning.