3v4l.org

run code in 300+ PHP versions simultaneously
<?php $show_data='a:4:{i:0;O:27:"WpProQuiz_Model_AnswerTypes":7:{s:10:"*_answer";s:12:"A . R rahman";s:8:"*_html";b:0;s:10:"*_points";i:1;s:11:"*_correct";b:1;s:14:"*_sortString";s:0:"";s:18:"*_sortStringHtml";b:0;s:10:"*_mapper";N;}i:1;O:27:"WpProQuiz_Model_AnswerTypes":7:{s:10:"*_answer";s:10:"Sonu Nigam";s:8:"*_html";b:0;s:10:"*_points";i:1;s:11:"*_correct";b:0;s:14:"*_sortString";s:0:"";s:18:"*_sortStringHtml";b:0;s:10:"*_mapper";N;}i:2;O:27:"WpProQuiz_Model_AnswerTypes":7:{s:10:"*_answer";s:10:"Lalu Yadav";s:8:"*_html";b:0;s:10:"*_points";i:1;s:11:"*_correct";b:0;s:14:"*_sortString";s:0:"";s:18:"*_sortStringHtml";b:0;s:10:"*_mapper";N;}i:3;O:27:"WpProQuiz_Model_AnswerTypes":7:{s:10:"*_answer";s:14:"Manmohan singh";s:8:"*_html";b:0;s:10:"*_points";i:1;s:11:"*_correct";b:0;s:14:"*_sortString";s:0:"";s:18:"*_sortStringHtml";b:0;s:10:"*_mapper";N;}}'; $user_answer=json_decode($show_data); $answer_index=array_search(1,$user_answer); $answers=unserialize($show_data->answer_data); $i=0; $correct_ans=""; $user_ans=""; foreach($answers as $ans) { if($ans->isCorrect()) $correct_ans=$ans->getAnswer(); if($i==$answer_index) $user_ans=$ans->getAnswer(); $i++; }
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught TypeError: array_search(): Argument #2 ($haystack) must be of type array, null given in /in/vu5G4:4 Stack trace: #0 /in/vu5G4(4): array_search(1, NULL) #1 {main} thrown in /in/vu5G4 on line 4
Process exited with code 255.
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Warning: array_search() expects parameter 2 to be array, null given in /in/vu5G4 on line 4 Notice: Trying to get property 'answer_data' of non-object in /in/vu5G4 on line 5 Warning: Invalid argument supplied for foreach() in /in/vu5G4 on line 9
Output for 7.3.32 - 7.3.33, 7.4.26
Warning: array_search() expects parameter 2 to be array, null given in /in/vu5G4 on line 4 Warning: Invalid argument supplied for foreach() in /in/vu5G4 on line 9
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25
Warning: array_search() expects parameter 2 to be array, null given in /in/vu5G4 on line 4 Notice: Trying to get property of non-object in /in/vu5G4 on line 5 Warning: Invalid argument supplied for foreach() in /in/vu5G4 on line 9
Output for 5.2.0 - 5.2.17
Warning: array_search(): Wrong datatype for second argument in /in/vu5G4 on line 4 Notice: Trying to get property of non-object in /in/vu5G4 on line 5 Warning: Invalid argument supplied for foreach() in /in/vu5G4 on line 9
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Fatal error: Call to undefined function json_decode() in /in/vu5G4 on line 3
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: json_decode() in /in/vu5G4 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Fatal error: Call to undefined function: json_decode() in /in/vu5G4 on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: json_decode() in /in/vu5G4 on line 3

preferences:
246.8 ms | 401 KiB | 327 Q