-2

In Perl, we could do like this:

foreach (....) {
   ..........
   ..........
   ..........
   my @tmp = ($x1,$x2,$y1,$y2);
   push(@target_array,\@tmp);  # Don't know how to translate this line to PHP, failed after several try with array_push
}

How to translate this into PHP?

Nissa
  • 215
  • 1
  • 7

1 Answers1

2

For add new array value you can use. i assume that you have length for loop.

$target_array = array();
for(....) {
   ..........
   ..........
   ..........
   $tmp = array($x1,$x2,$y1,$y2);
   $target_array[][] = $tmp;
}

or you can

for(....) {
       ..........
       ..........
       ..........
       $tmp = array($x1,$x2,$y1,$y2);
       array_push($target_array,$tmp);
}
Bharat Dangar
  • 527
  • 4
  • 20
  • If I don't have a counter $i, how can I do this (like the example in Perl)?Or I have to add a counter in order to know what's the current last element in the target_array? – Nissa Feb 14 '17 at 04:18
  • Yes you can push array in last by [ ][ ] in array.I update post – Bharat Dangar Feb 14 '17 at 04:23