2017-05-12 116 views
-2

我保存多個數組內數組內數組怎麼算內部數組數如何算多陣列計數PHP

Array ( 
[0] => Array ([table] => items [sku] => LUDM15) 
[1] => Array ([table] => items [sku] => SEZC64) 
) 

怎麼算內部數組數....

+0

使用用於循環來循環,並執行內部循環計數功能。 –

回答

0

循環遍歷數組然後count內陣列的長度:

$array = array(array('hi', 'hello'), array('hi', 'hello'), array('hi', 'hello')); 
foreach ($array as $singleArray){ 
    echo 'Count = ' . count($singleArray); 
} 
0
$mainArray = array ( 
    [0] => array ([table] => items [sku] => LUDM15) 
    [1] => array ([table] => items [sku] => SEZC64) 
) 
foreach ($mainArray as $subArray){ 
    echo count($subArray); 
} 

在foreach中你可以做任何你想要的單個子數的數量。

0

假設

$array1 is Array ( 
[0] => Array ([table] => items [sku] => LUDM15) 
[1] => Array ([table] => items [sku] => SEZC64) 
) 

$count = array(); 
foreach ($array1 as $key => $value) { 
    $count[] = count($value); 
} 

所有計數值將存儲在計數陣列