how to run loop inside array

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
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

how to run loop inside array

Post by manojsemwal1 »

Hai iam trying to run while loop inside array how to do this. code are like,...

Code: Select all

$xoption = array(

//Page => ('Answer Variable Name', 'Answer Label')
'1' => array('answer_1_var_name', 'Answer Name 1', 'answer_2_var_name', 'Answer Name 2', 'answer_3_var_name', 'Answer Name 3', 'answer_4_var_name', 'Answer Name 4'),
);
// i want to use 
$i=1;
$b=mysql_fetch_array($result2);

xoption = array(
'$i' => array('1', '$b[ans1]','2', '$b[ans1]''3', '$b[ans1]''4', '$b[ans1]'),
);
Thanks
Last edited by Weirdan on Mon Jun 07, 2010 9:36 am, edited 1 time in total.
Reason: added [syntax] tags
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: how to run loop inside array

Post by Jonah Bron »

I don't quite understand. Could you clarify what you're trying to accomplish?
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: how to run loop inside array

Post by markusn00b »

Yeh... what?

Also, remember to use quotes, be they single od double, around array indexes. If you don't, I will hunt you down!

Code: Select all

// Good
echo $array['your_key'];
// BAD!
echo $array[your_key];
Unless of course you have defined the appropriate constants (something I doubt).

Mark.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: how to run loop inside array

Post by Jonah Bron »

...I will hunt you down!...
And you don't want that: just take a look at his avatar! 8O
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

Re: how to run loop inside array

Post by manojsemwal1 »

Sorry for inconvenient
actually iam doing online exam assesment project in there iam trying to get value from database and store that in Array.
//without using database it will like....
session_start();

$total_pages = 6;

$xoption = array(

// Page => ('Answer Variable Name', 'Answer Label')

'1' => array('answer_1_var_name', 'Answer Name 1', 'answer_2_var_name', 'Answer Name 2', 'answer_3_var_name', 'Answer Name 3', 'answer_4_var_name', 'Answer Name 4'),
'2' => '',
'3' => '',
'4' => '',
'5' => '',
'6' => '',

);
echo '<form name="quiz" action="?page=' . $next_page . '" method="post">
<b>Questions PAGE ' . $current_page . '</b><br>
<input type="radio" name="' . $current_page . '" value="' . $xoption[$current_page]['0'] . '">' . $xoption[$current_page]['1'] . '<br>
<input type="radio" name="' . $current_page . '" value="' . $xoption[$current_page]['2'] . '">' . $xoption[$current_page]['3'] . '<br>
<input type="radio" name="' . $current_page . '" value="' . $xoption[$current_page]['4'] . '">' . $xoption[$current_page]['5'] . '<br>
<input type="radio" name="' . $current_page . '" value="' . $xoption[$current_page]['6'] . '">' . $xoption[$current_page]['7'] . '<br>

<br><input type="submit" name="submit" value="Continue to Page ' . $next_page . ' >"> ';


// i want to use fetch value from database.
$i=1;
$b=mysql_fetch_array($result2);

xoption = array(
'$i' => array('1', '$b[ans1]','2', '$b[ans1]''3', '$b[ans1]''4', '$b[ans1]'),
);

so how can i use it.....
Thanks
Post Reply