PHP syntax error when accessing a function return value with [0] -
originally code worked on personal development server:
$id = str_split(md5(mt_rand()), 16)[0]; but on server, (same version of apache , php, not know remote php.ini looks like), code threw error:
parse error: syntax error, unexpected '[' ... i "fixed" issue changing code to:
$id = str_split(md5(mt_rand()), 16); $id = $id[0]; then later changed original try , hunt down problem - original code worked! why first line of code throw syntax error? have tried searching explanation not know call type of issue.
using direct array dereferences not added until php 5.4.
you have assign temporary variable:
$arr = your_function(); $value = $arr[0]; see example #7 here: http://php.net/manual/en/language.types.array.php
Comments
Post a Comment