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条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条