Hot to store sql output to array in PHP? - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Sunday, June 25, 2023

Hot to store sql output to array in PHP?

Here is function:

protected function get_answers_with_question_id($id){
    global $wpdb;

    $sql = "SELECT *
            FROM {$wpdb->prefix}aysquiz_answers
            WHERE question_id=" . $id;

    $answer = $wpdb->get_results($sql, 'ARRAY_A');

    return $answer;
}

Call function:

    foreach ($questions_ids as $id) {
        
    $answers2[] = $this->get_answers_with_question_id2($id);
        
    }

Actual output:

[[{"answer":"1000"}],[{"answer":"1000"}],[{"answer":"1000"}]]

I need classic array: array(key=>value,key=>value,key=>value,etc.)



source https://stackoverflow.com/questions/76547247/hot-to-store-sql-output-to-array-in-php

No comments:

Post a Comment