- Feature Articles
- CodeSOD
- Error'd
-
Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
While that's an entirely acceptable way of doing it, I prefer an alternative which has a little duplication, but I find much easier to read...
$education = array("High School","Some College"); // and so forth foreach ($education as $ed) { if ($_SESSION["EducationID"]==$ed) { print "<input type='radio' name='EducationID' value='" . $ed . "' checked />"; } else { print "<input type='radio' name='EducationID' value='" . $ed . "' />"; } }Granted, if I was doing this in php from scratch, I'd probably use embedded HTML, rather than print statements,
<?php $education = array("High School","Some College"); // and so forth foreach ($education as $ed) { if ($_SESSION["EducationID"]==$ed) { ?> <input type='radio' name='EducationID' value='<?=$ed?>' checked />"; <?php } else { ?> <input type='radio' name='EducationID' value='<?=$ed?>' />"; <?php } } ?>Admin
Woah random_garbage, it's amazing how you used PHP to go from elegant to ugly in such a short step. I'd congratulate you, but really I should save the praise for PHP itself.
Admin
WTF