私は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[]
配列はすべての親のすべての子を格納しています。したがって、現在の親の子のみを格納するためにこの配列を更新する方法。つまり、新しい親の子を格納する前に配列を空にする方法。私を助けてください