Hello. Faced a problem. I need to write data to an array, but when it runs, it overwrites it. How to make so that there added the data, but did not rewrite? To make my data look like [0] => arrray ([0] => name1 [1] => name2)

$dataCategories = $modelCategories::find()->select(['*'])->orderBy(['name' => SORT_DESC])->all(); $arrayCategories = []; foreach($dataCategories as $arrayDataCategories ){ $arrayCategories[] = [ $arrayDataCategories->id => $arrayDataCategories->name ]; } echo"<pre>"; var_dump($arrayCategories); exit; 

    1 answer 1

     $items = []; foreach($dataCategories as $arrayDataCategories) { $items[$arrayDataCategories->id] = $arrayDataCategories->name; } $arrayCategories = []; array_push($arrayCategories, $items); 
    • I receive 2 arrays. And I need everything to be in the [0] array. - Denis Maksiura pm
    • I corrected the question a little. - Denis Maksiura 10:39 pm
    • Thank you very much! - Denis Maksiura 10:51 pm
    • @DenisMaksiura Please. Successes! The tick mark is to the left of the answer. - Igor