I am trying to get the result for the below query
$users = DB::select("SELECT FIND_IN_SET('l','a,b,c,d') as Res");
and while i do
return $users;
Here is my json
[{"Res":0}]
When i try to decode
it, it shows me the error
json_decode() expects parameter 1 to be string, array given
When i var_dump
i am getting as
array(1) { [0]=> object(stdClass)#773 (1) { ["Res"]=> int(0) } }
So, How can i get the result of the 'Res'
?
The solution is in the error:
json_decode() expects parameter 1 to be string, **array given**
That is, the result data is being returned as an array which based on your var_dump also contains your result object and subsequent data.
This should do it:
<?php
$data = $users[0]->Res
$decoded = json_decode($data);
Note that this is essentially just turning your JSON string into an object. You can use the second parameter to have it returned as an array if preferred:
<?php
$data = $users[0]->Res
$decoded = json_decode($data, true);