Jump to content

[SOLVED] looping help


dennismonsewicz

Recommended Posts

code:

$status_array = array('Pending', 'Followup', 'Approved', 'Completed', 'Rejected', 'Correction');
	for($i = 0; $i > sizeof($status_array); $i++) {
		foreach($status_array as $arr) {
			$option = '<option name=' . $arr . ' value=' . $arr . '>' . $arr . '</option>';
		}
}

 

I have a select that I am trying to echo out the options for by looping through the array... but when I echo out $options I get nothing... any ideas?

Link to comment
Share on other sites

You need to use double quotes for $option:

 

            $option = "'$arr";

 

I think you're using too many loops as well...

 

$status_array = array('Pending', 'Followup', 'Approved', 'Completed', 'Rejected', 'Correction');
   foreach($status_array as $arr)
       $option .= "$arr";

Link to comment
Share on other sites

both posts make valid points...no need for two loops

 

foreach ($arr as $value) {
    //your code here
}

 

also option is being overwritten each time in the loop...use +=

 

 $option += '<option name="'.$arr.'" value="'.$arr.'">'.$arr.'</option>';

Link to comment
Share on other sites

Just got back to this forum didn't know this post would bring forth such a discussion HAHA. yeah I work in an evironment of open source guys and .NET guys and we battle ALL the time. YAY for open source!

 

Tks for the help guys... I thought about it on the drive home tonight and yeah I only need the one loop. I don't know what I was thinking

Link to comment
Share on other sites

Just got back to this forum didn't know this post would bring forth such a discussion HAHA. yeah I work in an evironment of open source guys and .NET guys and we battle ALL the time. YAY for open source!

 

Tks for the help guys... I thought about it on the drive home tonight and yeah I only need the one loop. I don't know what I was thinking

 

Haha yeah, gotta love the open vs closed source battles.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.