Store array in while loop to use outside

后端 未结 4 456
星月不相逢
星月不相逢 2021-01-21 15:28

I would like to store value from while loop but not in multidimensional way :

 $movies_id = array();

 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
          


        
4条回答
  •  失恋的感觉
    2021-01-21 16:19

    Your code would not work in case of PHP version less than 5.4. In that case you can use the following.

            $movies_id = array();
    
            while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $id = $row['id'];
                $title_id = $row['title_id'];
                $movies_id[] = array($id => $title_id);
            }
    
            print_r($movies_id);
    

提交回复
热议问题