Jump to content

foreach help


dennismonsewicz

Recommended Posts

How would i turn the following code into a foreach statement?

 

echo '<div><input type="checkbox" name="pm1" class="checkbox" id="pm1" /> <label for="pm1">PM</label></div>';
echo '<div><input type="checkbox" name="designer1" class="checkbox" id="designer1" /> <label for="designer1">Designer</label></div>';
echo '<div><input type="checkbox" name="pm2" class="checkbox" id="pm2" /> <label for="pm2">PM</label></div>';
echo '<div><input type="checkbox" name="writer" class="checkbox" id="writer" /> <label for="writer">Writer</label></div>';
echo '<div><input type="checkbox" name="pm3" class="checkbox" id="pm3" /> <label for="pm3">PM</label></div>';
echo '<div><input type="checkbox" name="designer2" class="checkbox" id="designer2" /> <label for="designer2">Designer</label></div>';
echo '<div><input type="checkbox" name="pm4" class="checkbox" id="pm4" /> <label for="pm4">PM</label></div>';
echo '<div><input type="checkbox" name="christine" class="checkbox" id="christine" /> <label for="christine">Christine</label></div>';
echo '<div><input type="checkbox" name="pm5" class="checkbox" id="pm5" /> <label for="pm5">PM</label></div>';
echo '<div><input type="checkbox" name="designer3" class="checkbox" id="designer3" /> <label for="designer3">Designer</label></div>';
echo '<div><input type="checkbox" name="pm6" class="checkbox" id="pm6" /> <label for="pm6">PM</label></div>';
echo '<div><input type="checkbox" name="julie" class="checkbox" id="julie" /> <label for="julie">Julie</label></div>';
echo '<div><input type="checkbox" name="pm7" class="checkbox" id="pm7" /> <label for="pm7">PM</label></div>';
echo '<div><input type="checkbox" name="designer4" class="checkbox" id="designer4" /> <label for="designer4">Designer</label></div>';
echo '<div><input type="checkbox" name="pm8" class="checkbox" id="pm8" /> <label for="pm8">PM</label></div>';
echo '<div><input type="checkbox" name="proofreading" class="checkbox" id="proofreading" /> <label for="proofreading">Proofreading</label></div>';
echo '<div><input type="checkbox" name="pm9" class="checkbox" id="pm9" /> <label for="pm9">PM</label></div>';
echo '<div><input type="checkbox" name="layne" class="checkbox" id="layne" /> <label for="layne">Layne</label></div>';
echo '<div><input type="checkbox" name="pm10" class="checkbox" id="pm10" /> <label for="pm10">PM</label></div>';
echo '<div><input type="checkbox" name="programming" class="checkbox" id="programming" /> <label for="programming">Programming</label></div>';
echo '<div><input type="checkbox" name="pm11" class="checkbox" id="pm11" /> <label for="pm11">PM</label></div>';
echo '<div><input type="checkbox" name="testing" class="checkbox" id="testing" /> <label for="testing">Testing</label></div>';

Link to comment
https://forums.phpfreaks.com/topic/126482-foreach-help/
Share on other sites

yes it is a static number...

 

I reckon I was trying to come up with a lazy way of producing the information lol...

 

How would I save the post information into an array and then write a foreach statement that will loop through the results?

Link to comment
https://forums.phpfreaks.com/topic/126482-foreach-help/#findComment-654026
Share on other sites

You can do it like this:

 

<?php
$checkboxes = array( "designer1" => "Designer", "pm1" => "PM", "writer" => "Writer", "pm2" => "PM" );

if( is_array( $checkboxes ) )
{
     foreach( $checkboxes as $key => $value )
     {
           print( "<input type=\"checkbox\" name=\"" . $key . "\" class=\"checkbox\" id=\"" . $key . "\" /> <label for=\"" . $key . "\">" . $value . "</label></div> )";
     }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/126482-foreach-help/#findComment-654291
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.