Re: Using count() as an array index [message #178456 is a reply to message #178444] |
Tue, 19 June 2012 07:31 |
M. Strobel
Messages: 386 Registered: December 2011
Karma:
|
Senior Member |
|
|
Am 18.06.2012 19:43, schrieb Arno Welzel:
> Norman Peelman, 18.06.2012 12:32:
>
>> On 06/18/2012 03:46 AM, Arno Welzel wrote:
>>> Jerry Stuckle, 16.06.2012 20:44:
> [...]
>>> "{$anArray[count($anArray)]}\n";
> [...]
>>> Just because something is possible does not mean you have to use it ;-)
>>> Curly braces should only be used for code blocks and not to replace
>>> string concatenation.
>>>
>>
>> It's a little more than possible... it was designed this way. It's not
>> a replacement for string concatenation, it is used (in this context) for
>
> It is.
>
> The form
>
> "text {...something...} text"
>
> is generally the same as
>
> 'text' . something . 'text'
>
>
>> variable expansion within strings. If you don't want to use curly brace
>> syntax, then do it the long way, it's your choice. Me personally, I find
>> curly brace syntax much more readable than alot of '.'s and '/' escapes
>> like alot of people use.
>
> So:
>
> echo 'This is the result: '.$myclass->result;
>
> Is longer than
>
> echo "This is the result: {$myclass->result}";
>
> And why do i have to escape '/'? Seems have missed something ;-)
php > $c = new stdClass;
php > $c->result = 'NONE';
php > echo "this is the result: $c->result";
this is the result: NONE
php >
What are you arguing about? The braces have their uses, but you should know when they
are needed.
Maybe we should start an "obfuscated PHP contest" to mark the limits of code readability.
/Str.
|
|
|