Convert laravel object to array

前端 未结 14 858
名媛妹妹
名媛妹妹 2020-12-13 19:33

Laravel output:

Array
(
    [0] = stdClass Object
    (
        [ID] = 5

    )

    [1] = stdClass Object
    (
        [ID] = 4

    )

)

14条回答
  •  失恋的感觉
    2020-12-13 20:21

    Its very simple. You can use like this :-

    Suppose You have one users table and you want to fetch the id only
    $users = DB::table('users')->select('id')->get();
    $users = json_decode(json_encode($users)); //it will return you stdclass object
    $users = json_decode(json_encode($users),true); //it will return you data in array
    echo '
    '; print_r($users);
    

    Hope it helps

提交回复
热议问题