[英]Where is null coming from in this array?
我正在將php數組轉換為xml,如下所示:
$bigArray = $readConnection->fetchAll($query);
$doc = new DOMDocument();
$doc->formatOutput = true;
$r = $doc->createElement( "DATA" );
$doc->appendChild( $r );
foreach( $bigArray as $product )
{
$b = $doc->createElement( "ITEM" );
$product_type = $doc->createElement( "PRODUCT_TYPE" );
$product_type->appendChild(
$doc->createTextNode( $product['ProductType'] )
);
$b->appendChild( $product_type );
$sku = $doc->createElement( "SKU" );
$sku->appendChild(
$doc->createTextNode( $product['SKU'] )
);
$b->appendChild( $sku );
$r->appendChild( $b );
}
echo $doc->saveXML();
這將返回一個xml文檔,但是在最后添加了null,我認為這是導致我遇到其他問題的原因。 因此,例如在輸出的xml的底部,它看起來像:
</ITEM>
</DATA>
null
這個空值來自我是否可以看到的原始數組:
print_r($bigArray)
我看到類似的東西:
Array ( [0] => Array ( [ProductType] => simple [SKU] => 09423100010018 ) [1] => Array ( [ProductType] => simple [SKU] => 14552300010002 )) null
我從magento的一個類中調用它,例如:
class Foo_Model_Queryone extends Mage_Core_Model_Abstract
{
public function pprQuery() {
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$query = ("SELECT cpe.type_id AS 'ProductType',
cpe.sku AS 'SKU',
.....
Mage_Core_Model_Abstract類引起了問題,或者是更高級別的另一個類,正在輸出空值。
嘗試在Netbeans中使用Xdebug逐步解決它,並查看導致空值的原因。 我有興趣看到結果。
高溫超導
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.