# Thread: Iterating Array.

1. Hi,

This has been busting my brains for about 4 hours now and I can't get my head round it although it should be quite simple.

I have an organised set of data held in a string.
In simple terms this is what I'm trying to do.

Heres a simplified example of the string.

<br>
A1
B1
C1
<br>
A2
B2
C2
<br>
A3
B3
C3
<br>

Now I need to take the sring and get it to:

\$something . A1 . \$Something
\$something . A2 . \$Something
\$something . A3 . \$Something
\$something . B1 . \$Something
\$something . B2 . \$Something
\$something . B3 . \$Something
\$something . C1 . \$Something
\$something . C2 . \$Something
\$something . C3 . \$Something

I believe all in needs is a for() within another for() but it is absolutly driving me made.

Serious mental block!!

Cheers for the help.

2. Let me try if I understand what you wanna do

Code:
```\$ary = explode("<br>",\$input);
for (\$i=0;\$i<count(\$ary);\$i++)
{ \$ary[\$i] = explode("\n",\$ary[\$i]);
}

for (\$i=0;\$i<count(\$ary);\$i++)
{ echo("Somthing ".\$ary[\$i][\$i]." Something Else");
}```

3. Cheers for the help, I'll see if I can get it to work!

4. \$ary ? .. hehe, cute ! .. i use things like \$tempArray .. hehe

5. Hi,

Thanks for the help - finally got a solution that worked.

Just one thing: -

Can you explain the '\$ary[\$i][\$i]'

I've only ever come across the single[] never the double[][].

6. ChiliBoy: that's a multi-dimensional array, it allows you to store another "level" of data so to speak. Here's some more information:

http://www.php.net/manual/en/ref.array.php

7. one question:

is ary[\$i][\$j]
the same as ary[\$i] = array(\$j=>""); ?

8. Originally posted by boredboi
one question:

is ary[\$i][\$j]
the same as ary[\$i] = array(\$j=>""); ?
Yes, they're equivalent.

You could even go deeper and deeper ("array layers")
array[3][2][1][2][2].....

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•