我在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[]
数组存储了所有父母的所有孩子。那么如何刷新这个数组才能只存储当前的父子元素。即在存储新父亲的孩子之前如何使数组为空。请帮帮我
答案 0 :(得分:1)
如果您还没有尝试过,请尝试将数组初始化为null。可能是这样的事
$childlist = array();