如何清洁和更好下面的“零碎”的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