tags:

views:

47

answers:

2

Hello, I am creating a grid in GD and was wondering if this is the right way to do it.

I have 2 arrays. One contains all X values, the other contains all Y values.

foreach ($xpointsArray as $xvalue) {

  foreach ($ypointsArray as $yvalue) {

    // Draw point at coordinates $xvalue, $yvalue

  }
}

I just think there must be a more elegant way to set this up, and I would like to further access the points values without doing this every time.

+2  A: 

What you're doing is correct. There's possibly some more elegant solutions using a single two dimensional array, but either way you have to iterate through two loops.

Additionally, using a two dimensional array you could reference specific points by $Array[$x][$y] to get a specific point.

Ian Elliott
A: 

foreach, while, for are nice and I personally would prefer them, but since you are asking, what about using array_walk()?

array_walk($array1, "print_sudoku_field", $array2);
merkuro