0

I am working in Yii. I have following function in controller-

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>";
    }   
}

So i want to send parent and its children in json format. But $childlist[] array is storing all children of all parents. So how to refresh this array in order to store only current parents children . i.e. how to make array as empty before storing new parent's children . please help me

1 Answer 1

1

If you haven't already tried, try initializing the array to null. May be something like this
$childlist = array();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.