doukuilian8365 2014-06-04 14:02
浏览 233

PHP数组结构$ arr [($ arr [$ arr])]解释

I've been given some code and one line is:

 $key = $arr[($arr[$arr])];

I've never seen () in [] before, and Googling around I can't seem to find an explanation.

I don't know the value of $arr, but I wish to set it.

Doing:

$arr = 'blah';
$key = $arr[($arr[$arr])]; 

gives me Warning: Illegal string offset 'blah'

So I cannot print_r on it to find out what it looks like.

  • 写回答

1条回答 默认 最新

  • doupian6118 2014-06-04 14:04
    关注

    In general, there's nothing magical or strange here; the expression ($arr[$arr]) is equivalent to the expression $arr[$arr], just as (2) is equivalent to 2. At worst, the parens are redundant.

    That being said, keys cannot have array-type, so trying to look up an element in an array using itself as a key is .... meaningless....

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?