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 6603809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:03:54+00:00 2026-05-25T19:03:54+00:00

I have a foreach loop that looks like this, <?php $current_question = ; foreach

  • 0

I have a foreach loop that looks like this,

<?php $current_question = "";  
    foreach ($question_and_answers as $qa) : ?>  
        <?php $current_question == $qa['current_question']; ?>  
        <?php if($current_question == $current_question) : ?>  
            <input type="text" name="question[]" value="<?php echo $qa['question']; ?>"/>  
        <?php endif; ?>  
<?php endforeach; ?>

I am wanting to create an input field every time the loop hits a new question (a question gets returned numberous times, as a question can have numerous answers). What I have done does not seem to work.

I think seeing the array I working with help,

    Array
(
    [0] => Array
        (
            [question_id] => 2
            [question] => What is my name?
            [tests_test_id] => 2
            [answer_id] => 5
            [answer] => Simon
            [questions_question_id] => 2
            [correct] => true
        )

    [1] => Array
        (
            [question_id] => 2
            [question] => What is my name?
            [tests_test_id] => 2
            [answer_id] => 6
            [answer] => Dave
            [questions_question_id] => 2
            [correct] => false
        )

    [2] => Array
        (
            [question_id] => 2
            [question] => What is my name?
            [tests_test_id] => 2
            [answer_id] => 7
            [answer] => Fred
            [questions_question_id] => 2
            [correct] => false
        )

    [3] => Array
        (
            [question_id] => 2
            [question] => What is my name?
            [tests_test_id] => 2
            [answer_id] => 8
            [answer] => John
            [questions_question_id] => 2
            [correct] => false
        )

    [4] => Array
        (
            [question_id] => 3
            [question] => What is my surname?
            [tests_test_id] => 2
            [answer_id] => 9
            [answer] => Crawford
            [questions_question_id] => 3
            [correct] => true
        )

    [5] => Array
        (
            [question_id] => 3
            [question] => What is my surname?
            [tests_test_id] => 2
            [answer_id] => 10
            [answer] => Caine
            [questions_question_id] => 3
            [correct] => false
        )

    [6] => Array
        (
            [question_id] => 3
            [question] => What is my surname?
            [tests_test_id] => 2
            [answer_id] => 11
            [answer] => Rooney
            [questions_question_id] => 3
            [correct] => false
        )

    [7] => Array
        (
            [question_id] => 3
            [question] => What is my surname?
            [tests_test_id] => 2
            [answer_id] => 12
            [answer] => Ainley
            [questions_question_id] => 3
            [correct] => false
        )

    [8] => Array
        (
            [question_id] => 4
            [question] => What is my favourite colour?
            [tests_test_id] => 2
            [answer_id] => 13
            [answer] => Blue
            [questions_question_id] => 4
            [correct] => true
        )

    [9] => Array
        (
            [question_id] => 4
            [question] => What is my favourite colour?
            [tests_test_id] => 2
            [answer_id] => 14
            [answer] => Yellow
            [questions_question_id] => 4
            [correct] => false
        )

    [10] => Array
        (
            [question_id] => 4
            [question] => What is my favourite colour?
            [tests_test_id] => 2
            [answer_id] => 15
            [answer] => Green
            [questions_question_id] => 4
            [correct] => false
        )

    [11] => Array
        (
            [question_id] => 4
            [question] => What is my favourite colour?
            [tests_test_id] => 2
            [answer_id] => 16
            [answer] => Red
            [questions_question_id] => 4
            [correct] => false
        )

    [12] => Array
        (
            [question_id] => 5
            [question] => Who do I support?
            [tests_test_id] => 2
            [answer_id] => 17
            [answer] => Huddersfield Town
            [questions_question_id] => 5
            [correct] => true
        )

    [13] => Array
        (
            [question_id] => 5
            [question] => Who do I support?
            [tests_test_id] => 2
            [answer_id] => 18
            [answer] => Leeds United
            [questions_question_id] => 5
            [correct] => false
        )

    [14] => Array
        (
            [question_id] => 5
            [question] => Who do I support?
            [tests_test_id] => 2
            [answer_id] => 19
            [answer] => Manchester United
            [questions_question_id] => 5
            [correct] => false
        )

    [15] => Array
        (
            [question_id] => 5
            [question] => Who do I support?
            [tests_test_id] => 2
            [answer_id] => 20
            [answer] => Wolverhampton Wanderes
            [questions_question_id] => 5
            [correct] => false
        )

)

What I am trying to do, loop through the array, and everytime I meet a new question I want to outout a text input with the value of the question.

  • 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-05-25T19:03:55+00:00Added an answer on May 25, 2026 at 7:03 pm

    Try this.

    <?php $current_question = "";  
        foreach ($question_and_answers as $qa) : ?>  
            <?php if($current_question == $qa['current_question']) : ?>  
                <input type="text" name="question[]" value="<?php echo $qa['question']; ?>"/> 
                <?php $current_question = $qa['current_question']; ?>  
            <?php endif; ?>  
    <?php endforeach; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a json output that looks like this.. { XXXX: { name: Dalvin
In PHP I can use a foreach loop such that I have access to
Hello I have an array that looks like this, Array ( [cfi_title] => Mr
I have something that looks like this H1 H2 CHK1 N1 D1 CHK2 N2
I have a multi-dimensional array right now that looks like this: function art_appreciation_feeds() {
I have an xml that looks like this <words> <word>word1</word> <word>word2</word> <word>word3</word> <word>word4</word> </words>
I have some xml that looks like this: <?xml version=1.0?> <data> <items> <item><timestamp>2011-07-11T09:01:42Z</timestamp><title><![CDATA[ some
Let's say I have an object MyObject that looks like this: public class MyObject
I have a table that looks somewhat like this: CREATE TABLE foobar ( id
I frequently have code that looks something like this: if (itm != null) {

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.