0

I try to compare 2 array. 1 is from input::get and 1 is from query builder. Here is my code:

for ($k = 0; $k < $count; $k++) 
    { 
        $answer[] = Input::get('radio'.$k);
        $answerid[] = Input::get('input'.$k);

        $numberchoice[] = DB::table('numbers')->whereIn('questionid', array($answerid))->pluck('status');

        if ($answer == $numberchoice) 
        {
            $result[] = "1";
        }

        else
        {
            $result[] = "0";
        }
    }


    var_dump($answer); echo "<br>";
    var_dump($answerid); echo "<br>";
    var_dump($numberchoice); echo "<br>"; 

    $result = implode("%", $result);
    var_dump($result); echo "<br>"; 

    die();

i try to vardump every array to see what i got. I think the problem is at $numberchoice it keeps return me nothing. Although the $answer and $answerid is return correctly.

array(5) { [0]=> string(1) "1" [1]=> string(1) "1" [2]=> string(1) "1" [3]=> string(1) "0" [4]=> string(1) "1" } 
array(5) { [0]=> string(1) "3" [1]=> string(1) "6" [2]=> string(1) "8" [3]=> string(1) "1" [4]=> string(1) "2" } 
array(5) { [0]=> int(1) [1]=> NULL [2]=> NULL [3]=> NULL [4]=> NULL } 
string(9) "1%0%0%0%0" 

Please help. Thanks.

1 Answer 1

1

From what I can see, $answerid is already an array. But when you call ->whereIn('questionid', array($answerid)) you are wrapping existing array into another one. The correct whereIn call would be ->whereIn('questionid', $answerid)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.