Add data dynamically to an Array

前端 未结 10 679
南方客
南方客 2020-12-13 09:15

I want to add data to an array dynamically. How can I do that? Example

$arr1 = [
    \'aaa\',
    \'bbb\',
    \'ccc\',
];
// How can I now add another value?         


        
10条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 09:58

    Adding array elements dynamically to an Array And adding new element to an Array

    $samplearr=array();
    $count = 0;
    foreach ($rslt as $row) {
            $arr['feeds'][$count]['feed_id'] = $row->feed_id;
            $arr['feeds'][$count]['feed_title'] = $row->feed_title;
            $arr['feeds'][$count]['feed_url'] = $row->feed_url;
            $arr['feeds'][$count]['cat_name'] = $this->get_catlist_details($row->feed_id);
            foreach ($newelt as $cat) {
                array_push($samplearr, $cat);              
            }
            ++$count;
    }
    $arr['categories'] = array_unique($samplearr); //,SORT_STRING
    
    $response = array("status"=>"success","response"=>"Categories exists","result"=>$arr);
    

提交回复
热议问题