N
N
Nikita2020-05-29 15:55:43
PHP
Nikita, 2020-05-29 15:55:43

How to convert a multi-dimensional array to a one-dimensional array by a specific key?

The problem is probably solved easily, but I did not find the answer. Perhaps I'm asking the wrong question. From such a multidimensional array:

Array
(
    [0] => Array
        (
            [id] => 596
            [category] => 84
            [main] => 1
        )

    [1] => Array
        (
            [id] => 596
            [category] => 85
            [main] => 0
        )

)

I need to create a one dimensional array like this:
Array
(
    [0] => 84
    [1] => 85
)

Those. make an array selecting only values ​​with keys [category]
Sorry, I don’t know if I’m expressing myself correctly, but I think the question is clear.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-05-29
@MrNix21

array_column()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question