S
S
Stanislav Shabalin2020-05-09 21:53:37
PHP
Stanislav Shabalin, 2020-05-09 21:53:37

How to sort a multidimensional array?

There is a multidimensional array that needs to be sorted by the title field for all (for example, two) keys:
[travertino-romano-design]
[travertino-romano]

Array
(
    [travertino-romano-design] => Array
        (
            [0] => Array
                (
                    [title] => Black
                )

            [1] => Array
                (
                    [title] => Grey
                )

            [2] => Array
                (
                    [title] => Red
                )

            [3] => Array
                (
                    [title] => White
                )
        )

    [travertino-romano] => Array
        (
            [0] => Array
                (
                    [title] => Black
                )
            [1] => Array
                (
                    [title] => Grey
                )
        )
)


It seems like there is an array_multisort () function, but I can’t figure out how to cope with the task in this case. thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Shabalin, 2020-05-09
@Starck43

I figured it out myself))
Through the cycle I had to do:

foreach ($product_color_samples as $key => $value) {
      $title_col = array_column($product_color_samples[$key], 'title');
      array_multisort($title_col, SORT_ASC, $product_color_samples[$key]);
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question