0
我有此數組:如何獲取數組的值,但沒有指標
$order_list = array (array ("tangible", 1, 8, 1, 19000),
array ("tangible", 6, 2, 10, NULL),
array ("tangible", 1, 17, 1, 28000));
,我想組一起product_id ($order_list[2])
基於vendor_id ($order_list[1])
,我做到了。它看起來像這樣:
Array
(
[1] => Array
(
[0] => Array
(
[product_id] => 8
[pcs] => 1
[weight] => 115.00
)
[1] => Array
(
[product_id] => 17
[pcs] => 1
[weight] => 120.00
)
)
[6] => Array
(
[0] => Array
(
[product_id] => 2
[pcs] => 10
[weight] => 250.00
)
)
)
現在的問題是...
如何得到這個新的數組的值,而這個新的數組的索引包含vendor_id
?
我期待分別爲$new_array[0]
和$new_array[1]
的結果爲1或6。所以我可以創建for
循環。這仍然有可能嗎?以前感謝。
更新:我有這樣的代碼獲得的價值:
foreach ($order_array as $value) {
echo '<pre>';
print_r($value);
}
但是,不幸的是我得到這個輸出結果:
Array
(
[0] => Array
(
[product_id] => 8
[pcs] => 1
[weight] => 115.00
)
[1] => Array
(
[product_id] => 17
[pcs] => 1
[weight] => 120.00
)
)
Array
(
[0] => Array
(
[product_id] => 2
[pcs] => 10
[weight] => 250.00
)
)
我仍然不能得到1
和6
:-(
哪裏是你的廠商ID? –
嘗試使用foreach循環而不是循環 – Nikunj
@yahoo:vendor_id($ order_list [1]),在這種情況下它的值爲1和6 –