0
獲取單個值下面我有數組結果從一個數組
Array ([0] => Item Object ([name:protected] => My Super Cool Toy [price:protected] => 10.99))
我需要從這個數組得到[name:protected] => My Super Cool Toy
。
請告訴我如何得到它,
我將粘貼下面
class ShoppingCart
{
private $items = array();
private $n_items = 0;
function addItem(Item $item)
{
$this->items[] = $item;
$this->n_items = $this->n_items + 1;
print_r($this->items);
}
}
和
我的課class Item {
protected $name;
protected $price;
public function __construct($name, $price) {
$this->name = $name;
$this->price = $price;
}
public function getName() {
echo "item is $this->name";
return $this->name;
}
public function getPrice() {
return $this->price;
}
}
和
require_once('AddingMachine.php');
require_once('item.php');
//$arrayofnumbers = array(100,200);
$objectname = new ShoppingCart();
$objectname->addItem(new Item('My Super Cool Toy', 10.99));
$obname = new Item($items,44);
$obname->getName();
感謝