I have some markup that needs to be looped accordingly depending on the array, if it is multidimensional i have to loop it one way, if not i do not have to loop it.
As it is now i solve this by doing a big ‘ol if/else and print the “static” markup if its not multidimensional, and loop the markup if it is. This is ugly as heeell and makes me use 2 identical blocks of markup.
if (count($data_array) == count($data_array, COUNT_RECURSIVE))
{ block of html }
else
{ looped-almost same block of html }
Anyone got a better solution for this, i’d be happy to implement it instead 🙂
Edit: To clearify , i have a table that has properties looped, or not looped.
foreach($i as $b => $v)
$v['item']
where $v['item'] runs through the table if the array is multidimensional
if the array is not multidimensional i print the table with simply $i['item']
wich makes me use 2 identical html-blocks the only difference is the $v / $i
After you updated your answer, I think that simply checking for
$array['item']withissetcould solve your problem.Example:
Old answer:
Have you thought about
is_array?