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

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -