3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $answer_data=["0","1","0"]; $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($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.4.0 - 5.6.28, 7.0.0 - 7.1.0
Warning: array_search() expects parameter 2 to be array, null given in /in/L1pFA on line 5 Warning: unserialize() expects parameter 1 to be string, array given in /in/L1pFA on line 6 Warning: Invalid argument supplied for foreach() in /in/L1pFA on line 10
Output for hhvm-3.10.0 - 3.12.0
Warning: array_search() expects parameter 2 to be an array or collection in /in/L1pFA on line 5 Warning: unserialize() expects parameter 1 to be string, array given in /in/L1pFA on line 6 Warning: Invalid argument supplied for foreach() in /in/L1pFA on line 17
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/L1pFA on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/L1pFA on line 2
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/L1pFA on line 2
Process exited with code 255.