我在多个数组中存储数组如何在数组内计数
Array (
[0] => Array ( [table] => items [sku] => LUDM15 )
[1] => Array ( [table] => items [sku] => SEZC64 )
)
如何计算内部数组计数....
答案 0 :(得分:1)
假设
$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);
}
所有计数值都将存储在count数组
中答案 1 :(得分:0)
循环遍历数组,然后count
内部数组的长度:
$array = array(array('hi', 'hello'), array('hi', 'hello'), array('hi', 'hello'));
foreach ($array as $singleArray){
echo 'Count = ' . count($singleArray);
}
答案 2 :(得分:0)
$mainArray = array (
[0] => array ( [table] => items [sku] => LUDM15 )
[1] => array ( [table] => items [sku] => SEZC64 )
)
foreach ($mainArray as $subArray){
echo count($subArray);
}
在foreach中,您可以使用单个subArrays的计数执行任何操作。