[Typo3-dev] OT: Wonders of PHP

Ries van Twisk typo3 at rvt.dds.nl
Sun Nov 6 22:41:46 CET 2005


Bernhard Kraft wrote:

>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 !
>
>  
>
Nifty for sure,

but I think it's confusing and not clear programming style..

Ries




More information about the TYPO3-dev mailing list