3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ ['id' => 1, 'text' => 'text1', 'type' => 'A'], ['id' => 1, 'text' => 'text2', 'type' => 'B'], ['id' => 1, 'text' => 'text3', 'type' => 'C'], ['id' => 2, 'text' => 'text4', 'type' => 'A'], ['id' => 2, 'text' => 'text5', 'type' => 'B'], ['id' => 2, 'text' => 'text6', 'type' => 'C'], ['id' => 3, 'text' => 'text7', 'type' => 'A'], ['id' => 3, 'text' => 'text8', 'type' => 'B'], ['id' => 3, 'text' => 'text9', 'type' => 'C'], ]; $newArr = []; $ids = array_values(array_unique(array_column($arr, 'id'))); foreach ($ids as $key => $id) { foreach ($arr as $value) { if ($value['id'] === $id) { $newArr[$key]['id'] = $id; $newArr[$key][$value['type']] = $value['text']; } } } echo '<pre>'; print_r($newArr); echo '</pre>';

This is an error 500

Value for `_results` contains invalid data `array`


preferences:
153.91 ms | 2230 KiB | 14 Q