Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8092471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:17:24+00:00 2026-06-05T20:17:24+00:00

Problem: To get the index values of an array to print accordingly in value

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:17:25+00:00Added an answer on June 5, 2026 at 8:17 pm

    use the foreach loop
    http://www.w3schools.com/php/php_looping_for.asp

    and I think the sintax was

    foreach ($x as $key => $value)
    {
        echo $key . "<br />";
    }
    

    instead of for ($i = 1; $i <= count($array[‘question’]); $i++)

    LE: a better link is this one http://php.net/manual/en/control-structures.foreach.php

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem to get the values and text of the MultiSelectList to
I am beginner in ruby + rails. I have problem to get values in
I have the very common problem of creating an index for an in-disk array
Here's the link to the problem: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1130 This is my code and it works
I have an PHP array that looks something like this: Index Key Value [0]
Problem: to get the command working here. My domain is http://cs.edu.com/user/share_dir , but I
Hi I get problem retrieve XML data from SQL2000 server. The table structure is
I have a problem to get to SQL queries into one, the problem is
I am working with MyFaces/Primefaces and I have a problem to get information using
I get this problem when referring to OpenFEC (openfec.org)-functions in my code: anders@ubuntu:~/workspace/fectest$ gcc

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.