dongxieyou3314 2013-03-10 00:21
浏览 33
已采纳

PHP数组语法和操作说明

I have to convert a function from PHP to Java, and can use some clarification on PHP's array syntax, which has a few differences from Java. The PHP code is

$W; //array defined before and has values
$S = array();
$j = wsnum - 1; //integer value here

for ( ;  ; ){
  $S[] = $j
  $S[] = $W[$j]; 

}

My interpretation of this snippet is

  1. $S is initialized as an array of length 0
  2. $j is pushed to $S[0]
  3. The contents of $W[$j] are pushed to $S[1]

Is my interpretation correct, or am I barking up the wrong tree?

  • 写回答

1条回答 默认 最新

  • double2022 2013-03-10 00:23
    关注

    Your interpretation is totally correct.

    You can look at this post to learn more about php operators.

    The [] operator is a "push" operator. Which always put the value assigned at the end of a given array.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画