2

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?

Jason
  • 11,263
  • 21
  • 87
  • 181

1 Answers1

3

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.

Community
  • 1
  • 1
Hugo Dozois
  • 8,147
  • 12
  • 54
  • 58