[Typo3-dev] OT: Wonders of PHP

Bernhard Kraft kraftb at kraftb.at
Sun Nov 6 16:45:03 CET 2005


Hallo,


I'm currently working on a C++ project an begun to compare properties of php to C.

And when I came to the switch statement the first thing I thought about that it is
possible to switch(...) depending on a "string" type in PHP.

No I asked myself: What would PHP do if I switch an ARRAY ????

I typed "php" on my bash and typed in the following code:

-----------snip---------------------
<?php

$x = array(1, "foo" => 2, 3, array("a", "b"));

switch ($x)     {
        case array(1, 4, 8):
                echo "no\n";
        break;
        case array(1,3,2):
                echo "no\n";
        break;
        case array(1,2,3):
                echo "no\n";
        break;
        case array(3, 1,  "foo" => 2, array('a', 'b')):
                echo "no\n";
        break;
        case array("foo" => 2, 1, 3, array('a', 'b')):
                echo "wonderful\n";
        break;
        case array("foo" => 2, 1, 3, array('b', 'b')):
                echo "no\n";
        break;
}

?>
-----------snip---------------------

And as php is some kind of magic gadget toolset compilation it wonderully outputed "wonderful" !!!

Nifty things you could do with knowing that !

greets,
Bernhard




More information about the TYPO3-dev mailing list