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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:22:57+00:00 2026-05-23T23:22:57+00:00

I have following situation I have 2 arrys Following is answers array Array (

  • 0

I have following situation

I have 2 arrys

Following is answers array

Array ( 
    [0] => Array (
        [id] => 4e28258263d2c4
        [answer] => Study Accounting 
        [question_id_fk] => 4e28258262d100 
        [correct] => 0 
        [result_text] => Thats a right answer 
        [order] => 1 
    ) 
    [1] => Array ( 
        [id] => 4e28258266d896 
        [answer] => New York 
        [question_id_fk] => 4e28258265b752 
        [correct] => 0 
        [score] => 0.00 
        [result_text] => 
        [order] => 1
    ) 
    [2] => Array ( 
        [id] => 4e282582683870 
        [answer] => Yes 
        [question_id_fk] => 4e282582674ba0 
        [correct] => 0 
        [score] => 0.00 
        [hot_answer] => 0 
        [hot_email] => 
        [ordering] => 1 
        [result_text] => 
        [order] => 1 
    ) 
    [3] => Array ( 
        [id] => 4e282582698c23 
        [answer] => 2 
        [question_id_fk] => 4e282582689e80 
        [correct] => 0 
        [score] => 0.00 
        [hot_answer] => 0 
        [hot_email] => 
        [ordering] => 1 
        [result_text] => 
        [order] => 1 
    ) 
    [4] => Array ( 
        [id] => 4e2825826af072 
        [answer] => 1 
        [question_id_fk] => 4e2825826a0371 
        [correct] => 0 
        [score] => 0.00 
        [hot_answer] => 0 
        [hot_email] => 
        [ordering] => 1 
        [result_text] => 
        [order] => 1 
    ) 
    [5] => Array ( 
        [id] => 4e2825826d9638 
        [answer] => NYC 
        [question_id_fk] => 4e2825826ca998 
        [correct] => 0 
        [score] => 0.00 
        [hot_answer] => 0 
        [hot_email] => 
        [ordering] => 1 
        [result_text] => 
        [order] => 1 
    ) 
    [6] => Array ( 
        [id] => 4e2825826d9137 
        [answer] => Dallas 
        [question_id_fk] => 4e2825826ca998 
        [correct] => 0 
        [score] => 0.00 
        [hot_answer] => 0 
        [hot_email] => 
        [ordering] => 1 
        [result_text] => 
        [order] => 1 ) 
)

 

Here is Question List

 Array ( 
[0] => 4e28258262d100
[1] => 4e282582649464
[2] => 4e28258265b752 
[3] => 4e282582674ba0
[4] => 4e282582689e80 )

    foreach($questionList as $question){
        // I want to Get answers in array above which 
        // has $question.question_id = question_id_fk . One question can have multiple
        // answers

//Print Each question Id 
//Print answer , result_text and correct values from all answers found from AnswerList

     }

How do I search all answers for a question id from array . I need to get “correct” and “result_text” values for an answer .

  • 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-23T23:22:58+00:00Added an answer on May 23, 2026 at 11:22 pm
    $matches = array_filter ($answerList, function ($answer) use ($question) {
      return $question['id'] == $answer['question_id_fk'];
    });
    

    Now you can access every single entry.

    If you want to reduce the structures to an array of primtive values (the values you are looking for) you ca do something like

    $correct = array_reduce(
      $matches, 
      function ($result, $current) {
        $result[] = $current['correct'];
        return $result;
      }, 
      array()
    );
    

    Update

    I would suggest to reorder your $answerList

    $answerListOrderedByQuestionId = array_reduce (
      $answerList, 
      function ($result, $answer) {
        if (!array_key_exists($answer['question_id_fk'], $result))
          $result[$answer['question_id_fk']] = array();
    
        $result[$answer['question_id_fk']][] = $answer;
    
        return $result;
      }, 
      array()
    );
    

    This should now be an associative array with the key the question-id. Now you can easily access every single answer for a given question.

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

Sidebar

Related Questions

I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following situation. A main table and many other tables linked together with
I have following situation. In a constructor of a pseudo class I attach a
I have following situation (simplified, of course): MyDomain.groovy: class MyDomain { MyAnotherDomain anotherDomain //
I have following situation, String a=<em>crawler</em> <em> Yeahhhhh </em></a></h3><table; System.out.println(a.indexOf(</em>)); It returns the 11
I have following situation: String a = A Web crawler is a computer program
I have the following situation: I built an Access form with a subform (which
I have the following situation: class A { public: A(int whichFoo); int foo1(); int
I have the following situation: A user will define a certain filter on a
I have the following situation: I have a certain function that runs a loop

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.