php返回两个值数组对象

时间:2016-05-22 19:55:57

标签: php arrays

我想要做的是通过类中的对象设置两个属性然后获取此属性但我需要回显或打印值以确保,在fowling代码中有更多解释:

class product 
{
  var $title=" ";
  var $price=" "; 
  function __construct($title1,$price1)
  {
    $this->title=$title1;
    $this->price=$price1;
  }
  function set_title($newtitle){
    $this->title=$newtitle;
  }
  function get_title() {
    return $this->title;
  }
  function set_price($newprice)
  {
    $this->price=$newprice;

  }
  function getProductAtrribute ()
  {

     $x1=$this->title;
     $x2=$this->price; 

     return   $allattribute= array("$x1","$x2");


  }
}

$chair = new product(" small","chair");
$chair->getProductAtrribute(); 

在我获得属性后,我正在努力回应属性或打印它们的数组$ allattribute = arra(“$ x1,”$ x2“); 请帮助我如何打印这些价值。

2 个答案:

答案 0 :(得分:1)

以下内容应该有效:

print_r($chair->getProductAtrribute());

或者

var_dump($chair->getProductAtrribute());

答案 1 :(得分:0)

不确定你在问什么,但看起来像这样:

$prod = $chair->getProductAtrribute();
echo $prod[0].'<br>';
echo $prod[1];