jeudi 9 avril 2015

Add for loop based on conditional

I have a function which return two kind of array as below


// first array



$arr = array('P'=>array('val1'=>1,'val2'=>12),'T'=>array('val1'=>4,'val2'=>5));


//second array



$arr=array('South'=>array('P'=>array('val1'=>1,'val2'=>12),'T'=>array('va11'=>14,'val2'=>15),
'North'=>array('P'=>array('val1'=>6,'val2'=>9),'T'=>array('va11'=>23,'val2'=>22));


The second arr has a index more than the first array, which i want to loop and display


// my code



$arrStr = 'first';
if($flag ==1 )
$arrStr = 'second';
if($flag ==1)
for($retarr =>$directionIndex => $retArr) {
for(${$arrStr} as $ky=>$valArr) {
// so i have to close the for loop also based on condition , which does not work ,


} // end of first for
if($flag ==1)
} // end of second for


Is there a better way to loop on condition , or should i correct the function and split the whole display thing duplicated twice based on flag


Aucun commentaire:

Enregistrer un commentaire