<?php
function ugly_array() { return array(1, 2, 3, 4, 5); }
$arr = ugly_array();
echo $arr[2];
?>
not so ugly :)
now ... I want to get rid of the $arr temporary variable.
attempts (no more <?php and ?>; one attempt per line)
echo ugly_array()[2]; ## parse error
echo (ugly_array())[2]; ## parse error!
echo ((ugly_array())[2]); ## parse error
echo ({ugly_array()}[2]); ## parse error
echo ugly_array()([2]); ## parse error
echo +(ugly_array())[2]; ## parse error!!!!
echo '-'.(ugly_array() )[2]; ## parse error
and finally ... the ugly code that works
echo implode('', array_slice(ugl y_array(), 2, 1));
What am I missing here?
Can't I get an element of an array returned from a function?
What's so different about the array being named or unnamed?
--
..sig
function ugly_array() { return array(1, 2, 3, 4, 5); }
$arr = ugly_array();
echo $arr[2];
?>
not so ugly :)
now ... I want to get rid of the $arr temporary variable.
attempts (no more <?php and ?>; one attempt per line)
echo ugly_array()[2]; ## parse error
echo (ugly_array())[2]; ## parse error!
echo ((ugly_array())[2]); ## parse error
echo ({ugly_array()}[2]); ## parse error
echo ugly_array()([2]); ## parse error
echo +(ugly_array())[2]; ## parse error!!!!
echo '-'.(ugly_array() )[2]; ## parse error
and finally ... the ugly code that works
echo implode('', array_slice(ugl y_array(), 2, 1));
What am I missing here?
Can't I get an element of an array returned from a function?
What's so different about the array being named or unnamed?
--
..sig
Comment