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?

1 Answer 1

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.