2017-06-15 43 views
0

看看這些陣列PHP Arrays- 4個獨立的陣列,但只希望返回一個值

Array( 
[CompInvId] => 17 [Item] => w [Qty] => w [Tax_Rate] => 10 [Price] => w [ss] => w 
) 
Array( 
[CompInvId] => 17 [Item] => 4 [Qty] => 4 [Tax_Rate] => 10 [Price] => 4 [ss] => 4 
) 
Array( 
[CompInvId] => 17 [Item] => 4 [Qty] => 4 [Tax_Rate] => 10 [Price] => 4 [ss] => 4 
) 
Array(
[CompInvId] => 17 [Item] => 4 [Qty] => 4 [Tax_Rate] => 20 [Price] => 4 [ss] => 4 
) 

如何獲取剛剛從所有這些價值17?

+0

這些數組是如何存儲的?每個在一個單獨的變量?在數組中? – kabanus

+0

到目前爲止您嘗試過什麼? – hassan

回答

0

使用foreach通過陣列

foreach($arr as $key=>$val) // $arr is your array 
{ 
    $val['CompInvId']; 
} 
3
$a = array_column($array,'CompInvId'); 
print_r($a); 

這裏$陣列來迭代將是你的主陣列(在問題中提到)。

相關問題