$result = AssetModel::biGetRecords($userId);
The result is array of objects.
like this
array(100) {
[0]=>
object(stdClass)#1120 (3) {
["id"]=>
int(1058064)
["asset_id"]=>
string(16) "12345"
["name"]=>
string(22) "David"
}
[1]=>
object(stdClass)#1116 (3) {
["id"]=>
int(1058088)
["asset_id"]=>
string(16) "34567"
["name"]=>
string(6) "Smith"
so I use
$result = json_decode(json_encode($result), true);
to transfer array of std objects to array of arrays.
It works fine. But then when new records added in. Suddenly
$result = json_decode(json_encode($result), true);
instead of return array of array, it returns empty array now.
My guess is that some new records with some invalid characters that make json_encode returns invalid json string so the next step json_decode would not work?
echo "get results: ";
echo count($result);
$result = json_decode(json_encode($result), true);
echo " count data results again: ";
echo count($result);
the result is
get results: 397320 count data results again: 0
So my questions are
$result = json_decode(json_encode($result), true)is not error proof way to transfer array of objects to array of array?- if above case is true, what is the easiest way to transfer array of objects to array of arrays?
Thanks!
AssetModel::biGetRecords()returns and if it has private/protected properties. Can you mockup an example of what one of the object records looks like in your question? egvar_dump(current($result));