Solved

Iterate over variable sized two dimensional array?

Posted on 2010-08-12
2
216 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 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Testing a string condition in PHP 6 23
Using javascript confirmation for a delete in mysql 5 34
PHP AJAX Wordpress 9 21
Really simple no curl. Send a post 3 times 4 25
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

821 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