Page 1 of 1

Question about Strings

Posted: Sun Dec 11, 2011 1:17 pm
by Alex Heuman
Hey, I'm not quite understanding why the last line of this code

Code: Select all

echo "{$foo->$baz[1]}\n";
outputs I am bar. Why doesn't it output just "bar."

Code: Select all

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>the Good, the Loud, & the Angry</title>
    </head>
    <body>
    <?php
    class foo {
        var $bar = 'I am bar.';
    }
    
    $foo = new foo();
    $bar = 'bar';
    $baz = array('foo', 'bar', 'baz', 'quux');
    echo "{$foo->$bar}\n";
    echo "{$foo->$baz[1]}\n";
    ?>
    </body>
</html>

Re: Question about Strings

Posted: Sun Dec 11, 2011 1:23 pm
by Alex Heuman
Never mind, I get it now. Thanks.