NYCPHP Meetup

NYPHP.org

[nycphp-talk] Creating multidimensional arrays

Mark Armendariz nyphp at enobrev.com
Wed May 14 12:25:40 EDT 2003


Here's the code (rebooting my server)

<form>
<?php
	$questions = array();
	$questions[] = array('question' => 'Are you ugly?',
						 'options'  =>
array('Yes', 'No'),
						 'default'  => 'Yes');
	
	$questions[] = array('question' => 'Are you tall?',
						 'options'  =>
array('Yes', 'No'),
						 'default'  => 'Yes');
	
	$questions[] = array('question' => 'Are you funny?',
						 'options'  =>
array('Yes', 'No'),
						 'default'  => 'No');
						 
	$questions[] = array('question' => 'Will This Work?',
						 'options'  =>
array('Yes', 'No', 'I Hope So'),
						 'default'  => 'I Hope
So');
	
	foreach ($questions as $question_id => $question) {
?>
		<b><?= $question['question'] ?></b><br />
		<?php
			foreach($question['options'] as $option) {
				$display_checked = ($option ==
$question['default']) ? 'checked="checked"' : '';
		?>
				<input type="radio"
					 name="question_<?= $question_id
?>"
					 value="<?= $option ?>"
					 <?= $display_checked ?> /> <?=
$option ?><br />
		<?php
			}
		?>
		<br /><br />
<?php
	}
?>
</form>





More information about the talk mailing list