0

配列をクラス/オブジェクト構成に渡し、アクセス/返すか、操作する方法はありますか?

コード:

$affiliates = array(
        "clickbank" => "clickbankdata",
        "meepbank" => array(
                "meepbankdata" => "meep"
        )
);
class Affiliate {
    public $affiliates = array();

    public function __construct($array) {
        $this->affiliates = $array;
    }

    public function getAffiliatesArray() {
        return $this->$affiliates;
    }
}

$main = new Affiliate($affiliates);
print_r($main->getAffiliatesArray());
4

2 に答える 2

3
   public function getAffiliatesArray() {
            return $this->$affiliates;
        }

   should be

  public function getAffiliatesArray() {
        return $this->affiliates;
    }
于 2013-06-12T11:17:53.167 に答える
2

交換

return $this->$affiliates;
              ^
              |-------- Remove This 

return $this->affiliates;
于 2013-06-12T10:57:15.223 に答える