3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'category_id' => 1, 'question_id' => 1, 'option_id' => 2, 'title' => 'Do you wear glasses?', 'answer' => 'no' ], [ 'category_id' => 1, 'question_id' => 2, 'option_id' => 3, 'title' => 'Your hobbies ?', 'answer' => 'movies' ], [ 'category_id' => 1, 'question_id' => 4, 'option_id' => 8, 'title' => 'what is your status?', 'answer' => 'single' ], [ 'category_id' => 1, 'question_id' => 2, 'option_id' => 1, 'title' => 'Your hobbies ?', 'answer' => 'travel' ], ]; $result = []; foreach ($array as $row) { $compositeKey = $row['category_id'] . '_' . $row['question_id']; if (!isset($result[$compositeKey])) { $result[$compositeKey] = $row; } else { $result[$compositeKey]['answer'] .= ",{$row['answer']}"; } } var_export( array_values( $result ) );
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'category_id' => 1, 'question_id' => 1, 'option_id' => 2, 'title' => 'Do you wear glasses?', 'answer' => 'no', ), 1 => array ( 'category_id' => 1, 'question_id' => 2, 'option_id' => 3, 'title' => 'Your hobbies ?', 'answer' => 'movies,travel', ), 2 => array ( 'category_id' => 1, 'question_id' => 4, 'option_id' => 8, 'title' => 'what is your status?', 'answer' => 'single', ), )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
99.7 ms | 406 KiB | 5 Q