Snippets

Oleg Chulakov Studio Php reference sorting

Created by Владимир Самсонов
1
2
3
4
5
6
7
    array_filter(
        array_replace(
            array_flip($order),
            $items
        ),
        fn($value) => is_array($value)
    );
1
2
3
4
5
6
7
    $order = [8, 1, 4, 6, 2];
    $items = [
        2 => ['id' => 2, 'title' => 'Item 2'],
        4 => ['id' => 4, 'title' => 'Item 4'],
        6 => ['id' => 6, 'title' => 'Item 6'],
        8 => ['id' => 8, 'title' => 'Item 8'],
   ];

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.