Answer the question
In order to leave comments, you need to log in
How to parse only individual fields and not the whole object?
$userArray = ArrayHelper::toArray($user);
return json_encode(['answer'=>1,'customer'=>$userArray]); //парсятся все поля
return json_encode(['answer'=>1,'customer'=>$user]); //парсится объект с полями и методами
Answer the question
In order to leave comments, you need to log in
return json_encode(['answer'=>1, 'customer'=>array_intersect_key($userArray, ['name' => true, 'email' => true])]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question