json_encode returns [object object] instead of array [duplicate]

  foreach, json, php
$result = [];

$items = $connection->query("SELECT * FROM `budget` WHERE `type` = '".$btype."' ORDER BY `id` DESC");


foreach($items as $budget){

    $arr[] = array(
        'id'   =>  $budget['id'],
        'type' =>  $budget['type']
        );

    array_push($result, $arr);    
}

echo json_encode(['success' => $result], JSON_UNESCAPED_UNICODE);

it prints [object object], [object object], [object object], [object object] …

Could you tell me why and the way to solve it?

Source: Ask PHP

LEAVE A COMMENT