php - Loop through array that might be multi dimensional -


i might have following array()

array([     0 ]=>array([     part_id ]=>6[     part_user_id ]=>2[     part_department ]=>3[     part_category ]=>1[     part_subcategory ]=>1[     part_name ]=>sparepart[     part_qty ]=>1[     part_condition ]=>new[     part_description ]=>thisisadescription[     part_image ]=>images/parts/default.jpg)[     1 ]=>array([     part_id ]=>7[     part_user_id ]=>2[     part_department ]=>3[     part_category ]=>1[     part_subcategory ]=>1[     part_name ]=>sparepart[     part_qty ]=>1[     part_condition ]=>new[     part_description ]=>thisisadescription[     part_image ]=>images/parts/default.jpg)) 

from data have got mysql, same query might return more 1 row receive array()

array([     part_id ]=>7[     part_user_id ]=>2[     part_department ]=>3[     part_category ]=>1[     part_subcategory ]=>1[     part_name ]=>sparepart[     part_qty ]=>1[     part_condition ]=>new[     part_description ]=>thisisadescription[     part_image ]=>images/parts/default.jpg) 

i looping through output in html

foreach($myresults $row => $value){  } 

this loop work fine when receive more 1 row db. if receive 1 row run problem.

what best way me check have received in order loop or output dependent on result?

check if value array. if yes loop too.

if (is_array($value)) foreach ($value $value2) {} 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -