douyin8809 2014-12-31 16:51
浏览 33

解析错误:语法错误,意外']'[关闭]

I'm getting this error:

Parse error: syntax error, unexpected ']', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in your code on line 70

Line 70 is $message.

$random_keys=array_rand($lel,1);
$message[] = $lel[$random_keys[0]];

The whole code is here:

$message = array(); 
$lel = array(
    'Are you sure its the new year?', 
    'And i thought i was dumb', 'its not new year yet', 
    'LOL its ${date}', '...', '.....', '...', 'WUT', '.......', 
    'Ya drunk bruh ?', 'You sure you are not drunk ? what is 1+1 then ?'
);
$random_keys=array_rand($lel,1);
$message[] = $lel[$random_keys[0]];

Can we do it like this?

$message[] = $lel[rand(1,11)];

It still gives:

Parse error: syntax error, unexpected ']', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)

  • 写回答

1条回答 默认 最新

  • doushi3454 2014-12-31 16:54
    关注

    You are only picking one random key here:

    $random_keys=array_rand($lel,1);
    

    So you want to do this:

    $random_key = array_rand($lel,1);
    $message[] = $lel[$random_key];
    

    Working example: http://3v4l.org/PHWD8

    Though, since you're only picking one random key, and one random message, do you even need $message to be an array? I'd just do this:

    $message = $lel[array_rand($lel)];
    

    Working example: http://3v4l.org/jJKrG

    As for your parse error, there's something we're not seeing in the code you posted. Perhaps it is some other surrounding code, or perhaps you modified the code before pasting here? In any event, you can see that your exact code does not produce a parse error: http://3v4l.org/Io1jc

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题