Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 具有多个值的ArrayObject?_Php_Arrays_Multidimensional Array - Fatal编程技术网

Php 具有多个值的ArrayObject?

Php 具有多个值的ArrayObject?,php,arrays,multidimensional-array,Php,Arrays,Multidimensional Array,嘿,我有一个简单的循环,我试图创建ArrayObject,这样它就拥有了一个坐标系 我试图通过将Y坐标放置在X坐标中来减少重复数据,从而减少数据量 这就是我所尝试的: $object = new ArrayObject(); $xWidth=1; $yWidth=2; for ($x=0; $x < $xWidth; $x++) { $object[$x] = new ArrayObject(); for ($y=0; $y < $yWidth; $y++)

嘿,我有一个简单的循环,我试图创建ArrayObject,这样它就拥有了一个坐标系

我试图通过将Y坐标放置在X坐标中来减少重复数据,从而减少数据量

这就是我所尝试的:

$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];
   }
}

知道如何将第二个Y数字放入X阵列对象吗?

为什么不使用包含Y和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;

$object[$x][$y]什么都不做。更改
$object[$x][$y]
$object[$x][]=$y@WaleedKhan。。。。。。。。我知道这就是我问这个问题的原因…@alfasin啊,谢谢你!:)这就是我要找的@Dave那么为什么要使用ArrayObject而不是普通数组呢?
          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;