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
$S
is initialized as an array of length 0$j
is pushed to $S[0]
$W[$j]
are pushed to $S[1]
Is my interpretation correct, or am I barking up the wrong tree?
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.