update page now
Laravel Live Japan

Voting

: max(four, one)?
(Example: nine)

The Note You're Voting On

seb at example dot net
2 months ago
Be aware with array_multisort() and array_column() when you don't want to sort all columns. The last arg ...$rest is used to sort too!

<?php

$data = [
    ['id' => 5, 'name' => 'Marie'],
    ['id' => 7, 'name' => 'Lisa'],
    ['id' => 4, 'name' => 'Marie'],
    ['id' => 3, 'name' => 'Jean'],
    ['id' => 1, 'name' => 'Marie'],
    ['id' => 2, 'name' => 'Jean'],
];

array_multisort(
    array_column($data, 'name'), SORT_ASC, SORT_REGULAR, 
    $data,
);

/*
We could guess :

  3       Jean
  2       Jean
  7       Lisa
  5      Marie
  4      Marie
  1      Marie

But the result is :

  2       Jean
  3       Jean
  7       Lisa
  1      Marie
  4      Marie
  5      Marie

... id column has been sorted too!
*/

<< Back to user notes page

To Top