douqing5981 2013-08-16 02:59
浏览 87
已采纳

Windows上的语法错误,而不是Linux上的语法错误

The following code is giving me errors when run on windows with php version 5.3.5:

$dir_widgets = '/var/www/site-sp/dir1/filename.json';

error here:

$folder_name = array_reverse( explode( '/' , $dir_widgets ) )[ 1 ];

This is the error reported:

*Parse error*: syntax error, unexpected '[' in 

On GNU/Ubuntu 13.04 with PHP version 5.4.9 it works fine.

Can be the PHP version? Is it bad practice to do the following?

array_reverse( explode( '/' , $dir_widgets ) )[ 1 ]

Thanks.

  • 写回答

2条回答 默认 最新

  • donglu3243 2013-08-16 03:02
    关注

    Accessing an array index directly from a return value was added in PHP 5.4 hence why you are getting a syntax error with version 5.3. You'll need to save the return value from the function to a temporary variable and then access the index you want.

    Something like:

    $tmp_array = array_reverse( explode( '/' , $dir_widgets ) );
    $tmp_array[1] ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?