Why do I get an array in response after calling an array value by key

Viewed 29

I call a function, and I want to get a response with an array and two elements per key.

include_once($_SERVER['DOCUMENT_ROOT'].'/matsuka/_giveRandomQuestSearchPok.php');
$pokQ = QuestPoks::giveRandomQuestPok();

The function itself looks like this

public static function giveRandomQuestPok() {
    $sC = \Work::$sql->prepare('SELECT region FROM users WHERE id = ?');
    $sC->bind_param("i", $_SESSION['id']);
    $sC->execute();
    $dA = $sC->get_result();
    $region = $dA->fetch_assoc();

    if($region['region'] == 1){
        include_once($_SERVER['DOCUMENT_ROOT'].'/matsuka/randomPoks/Kanto.php');         
    }elseif($region['region'] == 3){
        include_once($_SERVER['DOCUMENT_ROOT'].'/matsuka/randomPoks/Hoenn.php');
    }
    
    $rarity = mt_rand(1,100);
    if($rarity == 1){
        $rare = 1;
        $object = \matsuka\Rare[mt_rand(0, count(\matsuka\Rare) - 1)];
    }elseif($rarity > 1 && $rarity <= 33){
        $rare = 2;
        $object = \matsuka\Uncommon[mt_rand(0, count(\matsuka\Uncommon) - 1)];
    }else{
        $rare = 3;
        $object = \matsuka\Common[mt_rand(0, count(\matsuka\Common) - 1)];
    }
    $array = array();
    $array['pok'] = $object;
    $array['rare'] = $rare;

    return $array;
}

After executing the function I want to assign two variables to control the result

$pok = $pokQ["pok"];
$rare = $pokQ["rare"];

But the handler still reads them as an array. And when I paste it into sql I get an Array, although I was hoping to get the array data by their corresponding key.

In var_dump I get quite a strange answer. I seem to see the required value of array called by the key, but on top of that I see another array, if I understand correctly.

int(401)
{
    "name":"\u0413\u0443\u0441\u0442\u0430\u0432",
    "actionQuest":"<img src=\"\/img\/quests\/7.webp\" class=\"quest\"> \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0432 \u0437\u0430\u0434\u0430\u043d\u0438\u0438 \u00ab\u041f\u043e\u043c\u043e\u0449\u044c \u0441\u0442\u0430\u0440\u043e\u043c\u0443 \u043f\u0440\u0438\u044f\u0442\u0435\u043b\u044e\u00bb. \u0417\u0430\u0433\u043b\u044f\u043d\u0438\u0442\u0435 \u0432 \u0410\u043a\u0432\u0430\u0431\u0443\u043a.",
    "question":"\u0422\u044b \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u0441 \u043c\u043e\u0438\u043c \u043f\u0440\u043e\u0448\u043b\u044b\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u0435\u043c. \u042f \u0445\u043e\u0440\u043e\u0448\u0435\u043d\u044c\u043a\u043e \u0438\u0437\u0443\u0447\u0438\u043b \u0442\u043e\u0433\u043e \u043f\u043e\u043a\u0435\u043c\u043e\u043d\u0430. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043d\u0435 \u043d\u0443\u0436\u0435\u043d: <div class=\"questPokemon\"><img src=\"\/img\/pokemons\/mini\/normal\/Array.webp\"> <div>#Array <\/div><\/div>"
}

Why does this happen and what is my mistake?

In the array I should only get 3-digit numbers under each key

0 Answers
Related