Question about Strings

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Alex Heuman
Forum Newbie
Posts: 5
Joined: Sat Dec 10, 2011 1:23 am

Question about Strings

Post 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>
Alex Heuman
Forum Newbie
Posts: 5
Joined: Sat Dec 10, 2011 1:23 am

Re: Question about Strings

Post by Alex Heuman »

Never mind, I get it now. Thanks.
Post Reply