我正在循环一个多维/嵌套数组,我得到以下结果,但是我想摆脱“1”:每个数组前面的索引号。
{"1":{"adjacencies":[{"nodeTo":"2"},{"nodeTo":"5"}],"data": {"$color":"#EBB056","$type":"star"},"id":1,"name":"rootWarbler<\/label>"},
"2":{"adjacencies":[{"nodeTo":"4"},{"nodeTo":"3"}],"data":{"$color":"#EBB056","$type":"star"},"id":2,"name":"rootJuniper tree<\/label>"},
"3":{"adjacencies":[null],"data":{"$color":"#EBB056","$type":"star"},"id":3,"name":"rootPuff Bird<\/label>"},
"4":{"adjacencies":[{"nodeTo":"5"},{"nodeTo":"3"}],"data":{"$color":"#EBB056","$type":"star"},"id":4,"name":"rootJackRabbit<\/label>"},
"5":{"adjacencies":[null],"data":{"$color":"#EBB056","$type":"star"},"id":5,"name":"rootMountain Lion<\/label>"},
"6":{"adjacencies":[{"nodeTo":"1"}],"data":{"$color":"#EBB056","$type":"star"},"id":6,"name":"rootBobcat<\/label>"}}
这是我的while循环
$previd = -1;
while($row=$result->FetchRow())
{
$id= (float)$row['n_id'];
$name = $row['name'];
$color1 = $row['color'];
$type1 = $row['type'];
$to= (float)$row['goingto'];
$thumb =$row['thumb']; //image path
if ($previd != $id) {
$previd = $id;
if ($previd != -1) {
array_push($array,$node);
}
$node[$id] = array(
"adjacencies" => array(),
"data" => array(
"$"."color" => $color1,
"$"."type" => $type1
),
"id" => $id,
"name" => "<img src='".$thumb."' height='25' width='25' alt='root'/><label>".$name."</label>");
}
if ($to != null) {
$node[$id]["adjacencies"][]=array("nodeTo" => "$to");
}
}
print_r($node);