1
我有以下嵌套数组。访问和打印嵌套数组
Array
(
[animals] => Array
(
[carnivores] => Array
(
[tiger] => Array
(
[eyes] => 2
[legs] => 4
)
[lion] => Array
(
[eyes] => 2
[legs] => 4
)
)
[herbivores] => Array
(
[deer] => Array
(
[eyes] => 2
[legs] => 4
)
[elephant] => Array
(
[eyes] => 2
[legs] => 4
)
)
)
)
我要处理上述阵列和使用foreach循环如下建立一个INSERT查询:
INSERT INTO `abc` (column1,column2,column3,column4, column5)
VALUES ('animals','carnivores','tiger','2','4');
.
.
.
.
INSERT INTO `abc` (column1,column2,column3,column4, column5)
VALUES ('animals','herbivores','elephant','2','4');
我怎样才能做到这一点。先谢谢您的帮助。
编写一个递归遍历数组的函数,并在迭代时将所有的键集合到一个数组中,然后您可以在查询中使用它。 – Rizier123
是的,你可以做到这一点,我们一个循环取内部数组的值。 –
为什么''狮子''和'[鹿]'键被处理时遗漏? – RomanPerekhrest