-1
我需要一個幫助。我有一種格式的數組值,但我需要使用PHP將其更改爲另一種格式。我在下面解釋我的代碼。如何使用PHP製作正確的數組格式
$sql=mysqli_query($connect,"select * from db_restaurant_basic where member_id='".$member_id."'");
while($row=mysqli_fetch_array($sql)){
if($row['image'] !=''){
$mul_image=$row['multiple_image'];
if($mul_image !=''){
$arr=explode(',', $mul_image);
for($i=0;$i<count($arr);$i++){
$data[]=array("image".$i=>$arr[$i]);
}
}
}
}
$result=array("data"=>$data,"imagepath"=>$imagepath);
echo json_encode($result,JSON_UNESCAPED_SLASHES);
上面的代碼給出了下面的輸出。
{"data":[{"image0":"87az6yooi0ms4i_de021b24.jpg"},{"image1":"d0ub9h8if4dkj4i_a6d6c48a.jpg"},{"image2":"3j9tx0m9xj0dx6r_1080970_1405444569670737_1257617107_n.jpg"}],"imagepath":"http://localhost/spesh/upload/"}
但我需要刪除所有的key
和預期的產出如下。
{"data":[{"87az6yooi0ms4i_de021b24.jpg"},{"d0ub9h8if4dkj4i_a6d6c48a.jpg"},{"3j9tx0m9xj0dx6r_1080970_1405444569670737_1257617107_n.jpg"}],"imagepath":"http://oditek.in/spesh/upload/"}
請幫我這麼做。
您的預期輸出是無效的JSON。 –
使用'foreach'循環並將結果推送到數組中? –
好吧,我如何顯示這個沒有關鍵。? – subhra