So, the other thread had a bit of fun behind it, so I figured maybe try starting another, similar thread? This one will be based around getting the number 8.
I'll follow the same structure from the other thread.
This would be the simplest method to get this answer, however be sure to read the rules!
As before, don't attempt the simplest method possible, but most inventive! See what you can come up with.
- eval and create_function functions are disallowed.
- 8 lines maximum but lines with only { and } on do not count towards that total. This does not include any echoes of the value.
- You must have only one semi-colon per line (;) unless of course it's used elsewhere apart from indicating the end of a line. Thus you're not allowed to fuse 2 lines together into 1. The exception is a for loop to where you're allowed 2.
- If PHP is going to store an integer in a variable (which I assume a lot of situations will) PHP will have to discover that number. An exception to this rule is the for loops first and last expressions. (Added this rule to make things a bit more entertaining)
- No PHP errors may be displayed. This includes Notices, Warnings, anything. error_reporting(-1); The only thing that can output is the number 8.
So however you end up doing it, the code must output the number 8.
I'll start off with two examples to show the diversity in which rules can be followed, although i'm sure many people will come up with their own interpretations!
PHP Code:
$var = 'I\'m the cookie monster!';
$var = strpos($var, "cookie");
echo $var;
PHP Code:
$string = 'aardvark';
$count = (int) false;
for($i = 0; $i < strlen($string); $i++)
$count++;
echo $count;