我有一個2d數組,它存儲我的數據庫表中的數據,然後將其放入一個json文件中。而且由於我不是在調用列名,因爲它是動態的,所以數組會自動添加它(表格單元格細節)的增量(數字),我不希望這樣。如何從二維數組中刪除數字php
這裏是JSON文件示例
{"0":"1","Fix":"1","1":"Sunday, May 11, 2014","Date":"Sunday, May 11, 2014","2":"FT","Time":"FT","3":"Cardiff City","Home":"Cardiff City","4":"1-2","Score":"1-2","5":"Chelsea","Away":"Chelsea","6":"Cardiff City Stadium (27,716)","Stadium":"Cardiff City Stadium (27,716)"}
我試圖除去它在PHP這樣
//Select everything in table
$query = mysql_query("SELECT * FROM ".$tablename);
//Storing the data into one arrays witk the ey => value
while($r=mysql_fetch_array($query)){
//Store the data as a 2d array
$json[] = $r;
}
foreach ($json as $key => $value) {
# code...
if(preg_match('/[0-9]/', $key)){
unset($json[$key]);
}else{
}
}
//Display the JSOn data
$o = fopen($tablename.'.json', 'w');
echo fwrite($o, json_encode($json));
fclose($o);
您目前的嘗試有什麼問題?對於'is_numeric()'而不是正則表達式,這聽起來像是一個很好的約會 – kero
你可以在'foreach'之前加上'print_r($ json)'來查看你的查詢的結果是什麼返回的? – ThomasEllis
這是真的我會加入英寸該腳本不插入數據在這裏它不喜歡在foreach循環中的東西 – user3210416