Get index values for an array to print in value attribute for radio buttons
- by kexxcream
Problem:
To get the index values of an array to print accordingly in value attribute of radio buttons.
The array $_SESSION['items']:
Array
(
[2] => Array
(
[category] => 2
[question] => Array
(
[6] => Källorna refereras separat
[7] => Vissa försök till sammanbindning
[8] => En del sammanfattningar
[9] => Olika forskningslinjer jämförs och sammanfattas
[10] => Kontraster, jämförelser, sammanfattningar; centrala likheter och skillnader framhävs
)
[title] => Integration av källorna
)
)
I have a PHP function that looks like this:
function itemsLayout ($array)
{
for ($i = 1; $i <= count($array['question']); $i++)
{
$form .= '<input type="radio" name="'.$array['category'].'" id="'.$array['category'].'" value="INDEX VALUE FOR QUESTION ARRAY HERE">';
}
return $form;
}
PHP code:
I get the index by using the following:
$key = key($_SESSION['items']);
$current = $_SESSION['items'][$key];
And I print the first index by using:
echo itemsLayout($current);
Question:
How do I get the index values 6, 7, 8, 9, 10 to print in the value attribute for each radio button?