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); $array_result = array_map(function ($v) use ($answers) { $v->answer = ($k = array_search($v->id, array_column($answers, 'id_question'))) !== false ? $answers[$k]['answer'] : null; return $v; }, $questions); print_r(json_encode($array_result, JSON_UNESCAPED_SLASHES));
Output for git.master, git.master_jit, rfc.property-hooks
[{"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"}]

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:
60.43 ms | 402 KiB | 8 Q