D
D
ddddd tttt2018-02-05 19:36:56
Yii
ddddd tttt, 2018-02-05 19:36:56

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]); //парсится объект с полями и методами

How to parse only certain fields?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Kim, 2018-02-05
@pashaa

return json_encode(['answer'=>1, 'customer'=>array_intersect_key($userArray, ['name' => true, 'email' => true])]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question