Php 具有多个值的ArrayObject?
嘿,我有一个简单的循环,我试图创建ArrayObject,这样它就拥有了一个坐标系 我试图通过将Y坐标放置在X坐标中来减少重复数据,从而减少数据量 这就是我所尝试的: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++)
$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;