【发布时间】:2014-11-22 09:21:36
【问题描述】:
朋友们,我设法从 php 代码中进行了以下输出
0 0 1 0 2 0 0
0 0 0 0 0 0 3
1 0 0 1 0 2 0
0 0 1 0 0 0 3
2 0 0 0 0 0 0
0 0 2 0 0 0 0
0 3 0 3 0 0 0
1==>3 3==>4 4==>7 7==>2 3==>6 1==>5
<html>
<?php
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
$result= array(array(0,0,1,0,2,0,0),array(0,0,0,0,0,0,3),array(1,0,0,1,0,2,0),
array(0,0,1,0,0,0,3),array(2,0,0,0,0,0,0),array(0,0,2,0,0,0,0),
array(0,3,0,3,0,0,0));
echo "<pre>";
for($k = 0; $k < 7; $k++){
for($j = 0; $j < 7; $j++){
echo $result[$k][$j],"\t";
}
echo "\n<br>";
}
$sum=0;
for($i = 0; $i < 7; $i++){
for($j = 0; $j < 7; $j++){
$sum += $result[$i][$j];
}
}
while( $sum > 0)
{
$i = 0;
while($i < 7){
$j=0;
while($j<7)
{
hm: if($result[$i][$j]!=0)
{ echo $i+1;
print "==>";
$result[$i][$j]=0;
$result[$j][$i]=0;
$i=$j;
$j=0;
echo $i+1;
print " ";
goto hm;
}
$j++;
}
$i++;
}
$sum=0;
for($i = 0; $i < 7; $i++){
for($j = 0; $j < 7; $j++){
$sum += $result[$i][$j];
}
}
}
//..................................................................
?>
</html>
预期输出
<markers>
<marker from="1" to="3"/>
<marker from="3" to="4"/>
<marker from="4" to="7"/>
<marker from="7" to="2"/>
<marker from="3" to="6"/>
<marker from="1" to="5"/>
</markers>
【问题讨论】:
-
您的问题似乎很广泛(而且不具体),根据您的问题和回答,您担心使用 DOMDocument 创建 XML。这已经得到了回答,我通过重复关闭使其可见。