3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 5.3.0 - 5.6.21, 7.0.0 - 7.1.0
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 hhvm-3.10.0 - 3.12.0
Warning: array_search() expects parameter 2 to be an array or collection in /in/vu5G4 on line 4 Notice: Cannot access property on non-object in /in/vu5G4 on line 5 Warning: Invalid argument supplied for foreach() in /in/vu5G4 on line 16
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.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.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