Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Iterate over variable sized two dimensional array?

Posted on 2010-08-12
2
Medium Priority
?
225 Views
Last Modified: 2013-12-13
How can I iterate over a variable sized two dimensional array?

In this array, the first dimensional has size 7, but the second is of a variable size.

Array ( [0] => Array ( ) [1] => Array ( [0] => A ) [2] => Array ( [0] => B ) [3] => Array ( [0] => B [1] => A ) [4] => Array ( [0] => C ) [5] => Array ( [0] => C [1] => A ) [6] => Array ( [0] => C [1] => B ) [7] => Array ( [0] => C [1] => B [2] => A ) )
0
Comment
Question by:pillmill
2 Comments
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 2000 total points
ID: 33422063
lbound(array, 1) to ubound(array, 1) for the first dimension and
lbound(array, 2) to ubound(array, 2) for the second?

Chris
0
 
LVL 2

Expert Comment

by:gtagliani
ID: 33422129
try this

for ( $i = 0 ; $i < count($arr) ; $i++ )
{
      echo "<br>";
      for ( $j = 0 ; $j < count($arr[$i]) ; $j++ )
      {
            echo $arr[$i][$j] . " - ";
      }

}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question