1

Dunno if it is the right title or not, but i'm struggling to do the following thing:

say I have this array

Array
(
    [0] => Array
        (
            [id_ptp] => 1
            [denumire_ptp] => Hrană uscată
        )

    [1] => Array
        (
            [id_ptp] => 2
            [denumire_ptp] => Hrană umedă
        )

    [2] => Array
        (
            [id_ptp] => 3
            [denumire_ptp] => Hrană vie
        )

)

how can I make it to become like this:

[
    '1' => 'Hrană uscată',
    '2' => 'Hrană umedă',
    '3' => 'Hrană vie',

]

Better question, is there a function that does that? Because I was not able to find it.

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
Timur Mengazi
  • 55
  • 1
  • 9

1 Answers1

3

array_column it is. Here is the one liner.

$result = array_column($your_array, 'denumire_ptp', 'id_ptp');

result : https://3v4l.org/qU0EU

Ijas Ameenudeen
  • 9,069
  • 3
  • 41
  • 54