php - What is the precidency and associtivity for increment operator and assignment operator for the block of code -


what precidency , associtivity increment operator , assignment operator block of code

$a=array(1,2,3); $b=array(4,5,6); $c=1;  $a[$c++]=$b[$c++];  print_r($a); 

as per execution outputs

 array        (              [0] => 1          [1] => 6          [2] => 3        ) 

but not able understand how array $a index 1 holds value of array $b index 2 value. can explain scenario how execution happens?

php (once again) different other languages in left part of assignment evaluates first. simple proof:

$a[print 1] = $b[print 2]; // print? 

according http://3v4l.org/, code:

$a = array(); $b = array(); $c = 1; $a[$c++]=$b[$c++]; 

generated following opcodes:

compiled vars:  !0 = $a, !1 = $b, !2 = $c line     # *  op                           fetch          ext  return  operands ---------------------------------------------------------------------------------    2     0  >   init_array                                       ~0                1      assign                                                   !0, ~0          2      init_array                                       ~2                3      assign                                                   !1, ~2          4      assign                                                   !2, 1    3     5      post_inc                                         ~5      !2          6      post_inc                                         ~7      !2          7      fetch_dim_r                                      $8      !1, ~7          8      assign_dim                                               !0, ~5          9      op_data                                                  $8, $9         10    > return                                                   1 

the opcode 5 left $c++, , opcode 6 right $c++. final assignment (opcode 8) evaluated as

$a[1] = $b[2]; 

which results in (1,6,3).


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -