Sir
Sir

Reputation: 8277

ArrayObjects with more than one value?

Hey I have simple loop that im trying to create ArrayObject so that it holds a co-ordinate system.

I'm trying to reduce the amount of data held by placing the Y co-ordinate in the X co-ordinate to reduce duplicate data.

This is what i tried:

$object = new ArrayObject();
$xWidth=1;
$yWidth=2;

for ($x=0; $x < $xWidth; $x++) {
        $object[$x] = new ArrayObject();

  for ($y=0; $y < $yWidth; $y++) {
        $object[$x][$y];
   }
}

The problem is the data comes out not what i expected... this is how i see the data:

ArrayObject Object
(
    [storage:ArrayObject:private] => Array
        (
            [0] => ArrayObject Object
                (
                    [storage:ArrayObject:private] => Array
                        (
                        )

                )

        )

)

Any idea how I can put the second Y numbers into the X ArrayObject?

Upvotes: 0

Views: 55

Answers (1)

youssDev
youssDev

Reputation: 90

why don't you just use an object that include y and x

          class coordinates{

             public __constructor($x, $y){
             $this->x = $x;
               $this->y = $y;
              }
              private $x;
            private $y;
            public function setX($x){
            $this->x = $x;
            }

             public function setY($y){
            $this->y = $y;
            }

            public function getX(){
            return $this->x;
            }

            public function getY(){
            return $this->y;
            }

            }

            $cordinate  = new coordinates($x, $y);

            $collectionCordinates[] = $cordinate;

Upvotes: 1

Related Questions