我试图检索使用SimpleXML从XML文件中的项目N多,把信息变成一个2维数组,如:检索N条记录从XML文件PHP
[0][name]
[0][image]
[1][name]
[1][image]
[2][name]
[2][image]
在这种情况下N个项目将6
我愿意做这两种方式,
1.抢第0-6键和值
2.或者从XML文件的随机6。
该xml文档有300条记录。
XML Example:
<xml version="1.0">
<info>
<no>1</no>
<name>Name</name>
<picture>http://www.site.com/file.jpg</picture>
<link>http://www.site.com</link>
</info>
</xml>
这是我到目前为止。读取xml会产生一个二维数组:
function getItems($file_id, $item_count=null)
{
switch ($file_id)
{
case '2':
$file = "http://xml_file.xml";
if ($xml = simplexml_load_file($file))
{
foreach ($xml->info as $info)
{
$var[] = array(
"Name" => (string)$info->name,
"Image" => (string)$info->picture);
}
return $var;
}
}
}
我可以使用for循环吗?或者以某种方式使用计数变量?
可以请你发布一些XML与该代码? – Gordon 2010-08-02 13:48:29
第二代码块从顶部... – rrrfusco 2010-08-02 14:48:36