我在 Yii 工作。我在控制器中有以下功能-
public function actiongetDnySubjectLink()
{
$contentTitleId=1;
$category=new Dnycontentcategories();
$record=$category->getCheckByParentTitleId($contentTitleId);
foreach ($record as $rec)
{
echo "</br>"."Main category is: " .$rec->childTitleId;
$parent=$category->getCheckByContentTitleId($rec->childTitleId);
echo $parent->englishTitle;
$record1=$category->getCheckByParentTitleId($rec->childTitleId);
foreach ($record1 as $rec)
{
echo "subcategory is :".$rec->childTitleId;
$child=$category->getCheckByContentTitleId($rec->childTitleId);
$childlist[]=$child->englishTitle;
echo $child->englishTitle;
}
echo CJSON::encode(array("parent"=>$parent->englishTitle,"child"=>$childlist))."</br>";
}
}
json
所以我想以格式发送父母及其子女。但是$childlist[]
数组存储了所有父母的所有孩子。那么如何刷新这个数组以便只存储当前父母的孩子。即如何在存储新父母的孩子之前使数组为空。请帮我