Yii Php: Getting values having a specific key in an associative array -
i have model/database table looks this
id | group_id| first_name | middle_name | last_name ------------------------------------------------------ | | | | ------------------------------------------------------
after retrieving model database:
say:
$people = personmodel::model()->findallbyattributes(array('group_id'=>$groupid));
and suppose i've retrieved 10 rows.. matching groupid given
i want store first_name of 10 rows matched.
i know can done by:
$personarray = array(); foreach($people $person){ $personarray[] = $person->first_name; }
but there way, e.g. php function same thing? thank you!
$criteria = new cdbcriteria; $criteria->compare('group_id', $groupid); $criteria->limit = 10; $people = personmodel::model()->findall($criteria); $personarray = $list = chtml::listdata($people, 'id','first_name');
the chtml::listdata() returns associative array like: ['id'] => 'first_name' (attributes of model)
Comments
Post a Comment