1
    $memberDetails = new MemberSearch();

I want to convert the object $memberDetails to an array . Any help would be appreciated. Thanks in advance

1
  • $arrayValues = $memberDetails->attributes; Commented Oct 12, 2017 at 9:12

1 Answer 1

1

You can use array helper

$memberDetails = new MemberSearch();
$results=ArrayHelper::toArray($memberDetails ,[
'common\models\Member'=>[
    'id',
    'name',
    ...
    ...                    
 ]
] ); 

or for a query, you can convert the result into an array

$memberDetails = new MemberSearch();
$dataProvider = $memberDetails->search(Yii::$app->request->queryParams);
$myArray= $dataProvider->all()->asArray();

Refer Yii2 ArrayHelper - toArray

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.