I was taking a look at another blog site I found today, and this one article caught my eye. It was about PHP variables. Now if you wanted to use a variable in a string, you would use one of the following:
| php code |
$food = "chicken";
echo "Bobby ate some . " $food;
echo "Bobby ate some $food";
|
Well, this blog article introduced me into another way of using a variable in a string:
| php code |
$food = "chicken";
echo "Bobby ate some {$food}";
echo "Bobby ate some ${food}";
|
Wtf is this PHP? How come you never told me about this before? I thought we had something special. :(
Source: Catch My Frame Article
So, now you're a cool kid ;-)
I use it all the time, but I find "Bobby ate some {$food}";
to be more unreadable than its worth so I usually seperate it to
because $food is usually some long object string
I'm still going to code using "Bobby ate some " . $food; though. I still think it to be at least a little bit easier to read.
Perhaps this is just a variation of using variable variables, but in this case its still just one var.
Good find LM