В рабочей среде, использующей инфраструктуру Yii1 и PHP 5.6.40, функция array_column возвращает пустой массив.
Массив представляет собой список записей CActiveRecord из другого отношения CActiveRecord HAS_MANY. На моем локальном компьютере (PHP 7.1.23) функция array_column работает, как и ожидалось. Если я не ошибаюсь, в документации говорится, что array_column доступен в PHP 5.6.40.
/**
* This is the model class for table 'my_active_record'.
*
* The following are the available columns in table 'my_active_record':
* @property integer $id
*
* The following are the available model relations:
* @property RelatedActiveRecord[] $relatedActiveRecords
*/
class MyActiveRecord extends CActiveRecord
{
public function relations()
{
return array(
'relatedActiveRecords' => array(self::HAS_MANY, 'related_active_records', 'my_active_record_id')
);
}
}
/**
* This is the model class for table 'related_active_record'.
*
* The following are the available columns in table 'related_active_record':
* @property integer $id
* @property integer $my_active_record_id
*
* The following are the available model relations:
* @property MyActiveRecord $myActiveRecord
*/
class MyActiveRecord extends CActiveRecord
{
public function relations()
{
return array(
'myActiveRecord' => array(self::BELONGS_TO, 'my_active_record', 'my_active_record_id')
);
}
}
$myActiveRecord = new MyActiveRecord();
print_r(array_column($myActiveRecord->relatedActiveRecords, 'id'));
Ожидаемые результаты: Array ( [0] => 1 [1] => 2 [2] => 3 )
Фактические результаты: Array ( ).