jeudi 23 janvier 2020

Sort array in Laravel

I am beginner in Laravel. I write my project in Laravel 5.8. I write code which generate array.

I have this array (result by dd($array)):

array:15 [▼
  0 => array:7 [▼
    "xkey" => 118
    "key" => 0
    "date" => "2020-01-19"
    "id" => 118
    "dishType" => "3"
    "name" => "Mięso z piersi kurczaka, bez skóry"
    "summaryQuantity" => "100"
  ]
  1 => array:7 [▼
    "xkey" => 251
    "key" => 0
    "date" => "2020-01-19"
    "id" => 251
    "dishType" => "3"
    "name" => "Olej rzepakowy"
    "summaryQuantity" => "23"
  ]
]

I need sort my result by "name" ASC.

i try:

ksort($fruits);

But it's not working. How can I make it?

This code help me:

array_multisort(array_column($shoppingArrayTmpData, 'name'), SORT_ASC, $shoppingArrayTmpData);


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire