我试图用foreach循环在数组中循环三个变量。
获取我的数组的模型是
function pieChart($limit = null, $conditions = null) {
//Get Data for PieChart
$this->RecordDrug->virtualFields['sum'] ='COUNT(*)';
$records = array();
$records=$this->RecordDrug->find('list',
array(
'conditions' => $conditions,
'fields' => array( 'Drug.drug', 'sum', 'Record.unit'),
'order' => array('sum' => 'desc'),
'limit' => $limit,
'contain' => array( 'Drug', 'Record' ),
'group' => 'Drug.Drug'
));
debug($records);
return $records;
}
我的调试给了我这个:
//Record.unit = a
//Drug.drug = b,
//sum = c,
array(
'a' => array(
'b' => 'c'
)
)
我希望能够在foreach循环中回显a,b和200。怎么可能?
答案 0 :(得分:0)
看起来你的数组的深度是2维。通常情况下,嵌套的foreach循环通常不是很好。尝试这个怎么样:
foreach ($Array AS $Arr1_Values){
if (is_array($Arr1_Values)){
foreach ($Arr1_Values AS $Arr1_Nest)){
echo $Arr1_Nest;
}
}else{
echo $Arr1_Values;
}
}