Reputation: 71
How to access the values in associative array in yii2. Note that this array is return by the ArrayHelper. I want to access the value of project_id . I tried to use getColumn($array, 'project_id') property from the ArrayHelper class. But it throws: unidentified index project_id
.
This below shown array is dumped using VarDumper of yii2:
[
[
[
'plot_id' => '9',
'plot_no' => '4',
'project_id' => '1',
'project' =>
[
'project_id' => '1',
'project_name' => 'City Dubaiq',
],
],
],
]
Upvotes: 0
Views: 2331
Reputation: 14459
You can get the value of project_id
in Yii2's ArrayHelper
like below(with your code):
echo \yii\helpers\ArrayHelper::getValue($array[0][0], 'project_id'); //1
Upvotes: 1