我有以下多維數組和我想的不同,如果該數組中只有一個子陣列或多個。獲取一個子陣列或者多個子陣列之間的差異多維數組
例如:
- 在陣列[1]只有一個子陣列[示例]
- 在陣列[2]有兩個子陣列[示例]
[content] => Array
(
[...]
[1] => Array
(
[example] => Array
(
[value] => GET THIS
[attr] => Array
(
[...]
)
)
)
[2] => Array
(
[example] => Array
(
[0] => Array
(
[value] => GET THIS
[attr] => Array
(
[...]
)
)
[1] => Array
(
[value] => GET THIS
[attr] => Array
(
[...]
)
)
)
)
我們從第一個數組中的[值]我想嘗試:
foreach ($content as $example) {
echo($content['example']['value']);
}
並獲得從第二陣列中的每個[值]我想嘗試:
foreach ($content as $example) {
foreach ($example as $values) {
echo($value['value']);
}
}
到目前爲止好,但我怎麼決定哪些函數來運行?我錯過了什麼嗎? 是否有一個if語句,它可以幫助我嗎?
喜歡的東西:
if(multiple sub-arrays){
// do first code example
} else {
// do second code example
}
我只是想一個方法來獲得所謂的[值]的所有值從數組中。
預先感謝您!
我看了你的問題兩次,仍不能完全得到的是你正在試圖解決這個問題。你能舉一個你期望得到的最終結果的例子嗎? –