Left-to-right evaluation?
Posted: Thu Jun 01, 2006 3:28 pm
If I'm interested in, say, the third element of a function's return array, I'd do this:
If I'm only interested in one of the elements of the array, some languages let me do this:
I know JavaScript lets you do all kinds of crazy stuff:
I can't get PHP to do the same thing. Is this because PHP doesn't support that kind of... "immediate evaluation," or am I simply not using the proper syntax? I've tried wrapping the function call in parentheses (a la ternary operation) and curly braces, but no success.
Also, if someone know the proper term for the functionality I'm talking about, I'd appreciate them mentioning it. I ran across it once several years ago, but I have since forgotten it and don't know where I found it.
Code: Select all
$third = explode(' ', 'blah blah blah');
print( $third[2] );Code: Select all
print( explode(' ', 'blah blah blah')[2] );Code: Select all
alert(oForm.elements[i].toFloat(3).toString().toUpper()); // not super useful, but it's the right ideaAlso, if someone know the proper term for the functionality I'm talking about, I'd appreciate them mentioning it. I ran across it once several years ago, but I have since forgotten it and don't know where I found it.