如何清潔和更好下面的「零碎」的PHP代碼:如何使這個代碼更短,更好
<?php
error_reporting(E_ALL);
require_once('app/Mage.php');
Mage::init();
Mage::getSingleton("core/session", array("name" => "frontend"));
$productList = array(
array(),
array(),
array()
);
$count = Mage::getSingleton('checkout/session')->getQuote()->getItemsQty();
$cart = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
$name = array();
$qty = array();
$price = array();
for ($i = 0; $i < $count; $i++) {
$name[$i] = $cart[$i]->getProduct()->getName();
$qty[$i] = $cart[$i]->getQty();
$price[$i] = $cart[$i]->getProduct()->getPrice();
$productList[$i] = array(
$name[$i],
$qty[$i],
$price[$i]
);
}
print_r($productList);
我想知道,如何美化這種frament。可能是我應該使用更短的數組初始化形式,在這種情況下一些標準的PHP函數等。
這屬於在http://codereview.stackexchange.com/。 – Fencer04