我正在循環一個多維/巢數組,我得到以下結果,但是我想擺脫每個數組前面的「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);
你在這裏使用'json_encode()'對嗎? –
我不明白。在擺脫1之後你想要什麼結果? (請在你的問題中編輯) – bestprogrammerintheworld
從什麼時候print_r輸出JSON? – Ultimater