Get index values for an array to print in value attribute for radio buttons

Posted by kexxcream on Stack Overflow See other posts from Stack Overflow or by kexxcream
Published on 2012-06-09T10:24:13Z Indexed on 2012/06/09 10:40 UTC
Read the original article Hit count: 255

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?

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays