The cycle passes, and you need to add information to the multidimensional array, for example:

name => Riga posY => 54.343434 posY => 57.343425 name => Daugavpils posY => 53.342346 posX => 56.456677 

Tried as follows, but retains only the last value in the loop:

  $arrPos = array( lat => $markPosY, lng => $markPosX ); 
  • one
    And where does the data for the cycle come from? And where does the name of the city go? - Ipatiev

2 answers 2

Because at every iteration you make "this variable is equal to this array". And at each iteration, the variable is completely overwritten by the new array. And you need to "add a new element to this variable (array)":

 $arrPos[] = [ lat => $markPosY, lng => $markPosX ]; 
     $arrPos[] = array( lat => $markPosY, lng => $markPosX );