Last active
June 1, 2017 09:44
-
-
Save i3or1s/2afc60855da5c482ce3d6854c5a71c63 to your computer and use it in GitHub Desktop.
Someone sometime ago asked me to print out both if and else. Print if and else
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* I have been asked to print out both if and else. | |
Put something instead of dots (...) so that the following code prints | |
string "TotallyImpossible" : | |
if (...) { | |
echo "Totally"; | |
} else { | |
echo "Impossible"; | |
} | |
*/ | |
// Their answer to this was | |
if (!print_r("Totally")) { | |
echo "Totally"; | |
} else { | |
echo "Impossible"; | |
} | |
echo PHP_EOL; | |
// While on the other hand i got this "PHP magic" to work | |
$var = 1; | |
if(preg_match('#.+?(?={)\{(?P<if>.+?)(?=})#s', @array_pop(@explode("matches['else']", file_get_contents(__FILE__))), $matches) && eval($matches['if']) != NULL) { | |
echo "-- If true --".PHP_EOL; | |
$var++; | |
echo $var.PHP_EOL; | |
} else { | |
echo "-- If false --".PHP_EOL; | |
$var++; | |
echo $var.PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment