Yii2中的对象转数组: $video = Video::find()->asArray()->one();
把数组转化成任何你想要的对象类型的数组:
function array2object($array) {
$aboutVideoArr = array();
if (is_array($array)) {
foreach ($array as $value) {
$video = new Video();
foreach ($value as $key => $val) {
$video->$key = $val;
}
array_push($aboutVideoArr, $video);
}
} else {
$video = $array;
}
return $aboutVideoArr;
}
把对象转化成普通的数组:
function object2array($object) {
if (is_object($object)) {
foreach ($object as $key => $value) {
$array[$key] = $value;
}
}
else {
$array = $object;
}
return $array;
}