You are here: Create a multidimensional array from XML doc « PHP Programming Language « IT news, forums, messages
Create a multidimensional array from XML doc

Posted by Chuy08 on 02/16/07 21:02

Currently I have the following XML document:

<Programs>
<Program>
<ProductTypeName>30 Yr Fixed</ProductTypeName>
<Rate>6.250</Rate>
<APR>6.274</APR>
<InvestorName>Helos</InvestorName>
<Payment>2832.298</Payment>
</Program>
<Program>
<ProductTypeName>30 Yr Fixed</ProductTypeName>
<Rate>9.250</Rate>
<APR>9.293</APR>
<InvestorName>Avalon</InvestorName>
<Payment>3784.306</Payment>
</Program>
<Program>
<ProductTypeName>5/1 Arm</ProductTypeName>
<Rate>6.375</Rate>
<APR>6.399</APR>
<InvestorName>Carl1</InvestorName>
<Payment>2869.802</Payment>
</Program>
</Programs>

I load it up in a domdocument and iterate through it with the following:

$returns = array();
for($i = 0; $i < $xmlproducttype->length; $i++)
{
$returns[$i]['ProductTypeName'] =
$xmlproducttype->item($i)->nodeValue;
$returns[$i]['InvestorName'] =
$xmlinvestorname->item($i)->nodeValue;
$returns[$i]['Rate'] = $xmlrate->item($i)->nodeValue;
$returns[$i]['APR'] = $xmlapr->item($i)->nodeValue;
$returns[$i]['Payment'] = $xmlpayment->item($i)->nodeValue;
}

Giving me the following style array:

$returns['0']['ProductTypeName']

What I need to figure out is how to iterate through this XML document to
make an array where the unique ProductTypeName, which can be repeated many
times, is the key name and the values are the other elements in the xml
document. I am looking to get something like the following:

$records=array(
array('30 year fixed' =>
array('InvestorName' => Carl1, 'Rate'=>6.0, ...)
array('InvestorName' => Avalon, 'Rate'=>6.0, ...)

print_r($records['30 year fixed']['InvestorName']) = Avalon



--
Posted via a free Usenet account from http://www.teranews.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация