3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $Prepetrators = array(); $nos = array(); $preparatorsToBeShown; $PreparatorArray = array(); $criminalList = array(); $cardShown = array(); $flag1; $flag2; $flag3; $criminalList[0] = "a"; $criminalList[1] = "b"; $criminalList[2] = "c"; $criminalList[3] = "d"; $criminalList[4] = "e"; $criminalList[5] = "f"; $criminalList[6] = "g"; $Prepetrators = selectPrepetrators(); $Prepetrators[0] = "b"; $Prepetrators[1] = "f"; $Prepetrators[2] = "e"; function selectPrepetrators() { global $Prepetrators,$nos,$preparatorsToBeShown,$PreparatorArray,$criminalList,$cardShown; $PrepetratorsNames = array(); $i = 0; while($i!=3) { $no = rand(0,5); if(in_array($no,$nos) != 1) { $nos[] = $no; $i++; } } for($j = 0;$j< count($nos) ; $j++) { $number = $nos[$j]; $name = $criminalList[$number]; $PrepetratorsNames[] = $name; } for($j = 0;$j< count($nos) ; $j++) { $number = $nos[$j]; $name = $criminalList[$number]; $PreparatorArray[] = $name; } return $PrepetratorsNames; } function showCard() { global $Prepetrators,$nos,$preparatorsToBeShown,$PreparatorArray,$criminalList,$cardShown; $cardToBeDisplayed = array(); $preaparatorOnCard = array(); $i = 0; // global $preparatorsToBeShown = rand(1,2); while($i != $preparatorsToBeShown ) { $no = rand(0,3); if( in_array($no,$preaparatorOnCard)!= 1) { $preaparatorOnCard[] = $no; $i++; } } $no = 0; $no = 3 - $preparatorsToBeShown; $y = 0; $fakePrepators = array(); while($y != $no) { $no1 = rand(0,5); while((in_array($no1,$nos) == 1 )|| (in_array($no1,$fakePrepators) == 1) ) { $no1 = rand(0,5); } $fakePrepator = $no1; $fakePrepators[] = $fakePrepator; $y++; } for($num = 0 ;$num <count($cardShown) ; $num++) { ///////////////////////////Unsetting array logic ////////////////// unset($cardShown); ///////////////////////////////////////////////////////////////// } //////////////////set the array /////////// $cardShown = array_values($cardShown); ////////////////////////////////////////// for($k =0; $k<$preparatorsToBeShown ;$k++) { $a = $PreparatorArray[$k]; $cardShown[] = $a; } for($d=0;$d<count($fakePrepators);$d++) { $fakePrepator = $fakePrepators[$d]; $fakePrePator = $criminalList[$fakePrepator]; $cardShown[] = $fakePrePator; } for($k =0;$k < count($fakePrepators);$k++) { $var = $fakePrepators[$k]; } echo " the card shown is <br>"; for($k =0;$k < count($cardShown);$k++) { $var = $cardShown[$k]; } $var1 = $cardShown[0]; $var2 = $cardShown[1]; $var3 = $cardShown[2]; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo "<font color='560404'>...................................................................................................................................................................</font>"; echo "<font color='#FFFFFF' size='+1'>Actual perpetrators out of these are -----> </font>"; echo "<font color='#FFFFFF' size='+1'>$preparatorsToBeShown</font>".'<br>'; echo '<br>'; echo "<font color='560404'>....................................................................................................................................</font>"; echo'<input type="text" align="middle" name="something" value="'.$var1.'"/>'; echo '<input type="text" align="middle" name="something" value="'.$var2.'"/>'; echo '<input type="text" align="middle" name="something" value="'.$var3.'"/>'; } if (isset($_POST['show'])) { echo "function called<br> "; showCard(); } if(isset($_POST['form11'])) { if (isset($_POST['enter1'])) { $input1 = $_POST['enter1']; if(in_array($input1, $Prepetrators)==1) { $flag1 = 1; } else { $flag1 = 0; } } if (isset($_POST['enter2'])) { $input2 = $_POST['enter2']; if(in_array($input2, $Prepetrators)==1) { $flag2 = 1; } else { $flag2= 0; } } if (isset($_POST['enter3'])) { $input3 = $_POST['enter3']; if(in_array($input3, $Prepetrators)==1) { $flag3 = 1; } else { $flag3 = 0; } } echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo "<font color='560404'>...............................................................................................................................................................................</font>"; echo "<font color='#FFFFFF' size='+1'>The actual perpetrators are</font>";; echo '<br>'; echo '<br>'; echo "<font color='560404'>....................................................................................................................................</font>"; echo'<input type="text" align="middle" name="something" value="'.$Prepetrators[0].'"/>'; echo '<input type="text" align="middle" name="something" value="'.$Prepetrators[1].'"/>'; echo '<input type="text" align="middle" name="something" value="'.$Prepetrators[2].'"/>'; if($flag1 == 1 && $flag2 == 1 && $flag3 == 1 ) { echo '<script type="text/javascript"> window.alert("You Found Them ") </script>'; } else { echo '<script type="text/javascript"> window.alert(" Sorry your answer is not correct ") </script>'; } } ?>
Output for 5.3.0 - 7.1.0