Problems with Loops / For's / Cycles

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rubahfgouveia
Forum Newbie
Posts: 1
Joined: Thu Aug 12, 2010 9:35 pm

Problems with Loops / For's / Cycles

Post by rubahfgouveia »

Hey guys, i'm kind of stuck here, and was wondering if anyone could give me a hand. I'm kind of new in PHP, and currently I'm experiencing a cycle problem.

I have a php page that recieve a list of variable number of arrays (it can be one array, or even 10), and what i want the cycle to do is, is to print out each value contained in each array.

Example of variables recieved through POST:
([course1] => Array ( [0] => BBB [1] => YA ) [course2] => Array ( [0] => EWA) [course3] => Array ( [0] => aaa))

Code: Select all


	for($i = 0; $i < $num_course; $i++) // num_course is the number of arrays (course0,course1) that are recieved
			{
                  
                 $test = "course".$i;
     
                 for($x = 0; $x < sizeof([color=#FF4000]$test[/color]); $x++)
                   {

                   echo("[color=#FF4040]$test[$x][/color]");
                   }

                        }

I think that the problem here is the $test variable. I don't what the sizeof($test), but yes the sizeof(course0, course1,etc) .. and also, i don't what to echo the $test[$x] variable, but yes the $course0[$x], $course1[$x], etc...


i hope i made myself clear :?

I would glady appreciate any help!
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Problems with Loops / For's / Cycles

Post by requinix »

The problem is not using a rather nice feature of PHP's input handling routines.

Code: Select all

<input type="radio" name="course[0][]" value="BBB" /> BBB
<input type="radio" name="course[0][]" value="YA" /> YA

<input type="radio" name="course[1][]" value="EWA" /> EWA

<input type="radio" name="course[2][]" value="aaa" /> aaa

Code: Select all

print_r($_POST);
Post Reply