3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array_question = '[ { "id": "8", "question": "Shop sign/billboard " }, { "id": "10", "question": "Pylon" }, { "id": "11", "question": "Banner" }, { "id": "12", "question": "Sport" }, { "id": "14", "question": "Matic " }, { "id": "16", "question": "Cub" } ]'; $array_answer = '[ { "id": "1b9fa84e-0f2f-11e9-b673-005056be36b2", "answer": "3", "id_question": "16" }, { "id": "bc82c3fd-0f2e-11e9-b673-005056be36b2", "answer": "1", "id_question": "11" }, { "id": "cc9363f1-0f2e-11e9-b673-005056be36b2", "answer": "3", "id_question": "12" }, { "id": "f1dfa8b5-0f2e-11e9-b673-005056be36b2", "answer": "1", "id_question": "14" } ]'; $questions = json_decode($array_question); $answers = json_decode($array_answer, true); function my_array_column($array, $column) { return array_map(function ($v) use ($column) { return $v[$column]; }, $array); } $array_result = array_map(function ($v) use ($answers) { $v->answer = ($k = array_search($v->id, my_array_column($answers, 'id_question'))) !== false ? $answers[$k]['answer'] : null; return $v; }, $questions); echo str_replace('\/', '/', json_encode($array_result));

Shows result from various feature-branches currently under review from the php developers. Contact me to have additional branches featured.

Output for branch partials
[{"id":"8","question":"Shop sign/billboard ","answer":null},{"id":"10","question":"Pylon","answer":null},{"id":"11","question":"Banner","answer":"1"},{"id":"12","question":"Sport","answer":"3"},{"id":"14","question":"Matic ","answer":"1"},{"id":"16","question":"Cub","answer":"3"}]

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