Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zaster's avatar

Get only the values from the array

Collection {#439 ▼
  #items: array:3 [▼
    0 => 2
    1 => 3
    2 => 4
  ]
}

Need to get something like this [2, 3, 4]

0 likes
1 reply
Cronix's avatar
Cronix
Best Answer
Level 67
$collection = collect([0 => 2, 1 => 3, 2 => 4]);

dump($collection->values()->toArray());
1 like

Please or to participate in this conversation.