我試圖打電話array_push添加通過GET請求我的JSON數組保存註冊ID爲我的GCM客戶端發送的數據以JSON數組添加對象與PHP
<?php
//read current regids
$myfile = fopen("regids.json", "r") or die("Unable to open file!");
$current_regids = fread($myfile,filesize("regids.json"));
// decode json
$decoded_json= json_decode($current_regids);
//save to php format array
$array = array($decoded_json);
//close file
fclose($myfile);
//get registration id
$regid = $_GET["regid"];
//push new reg id into array
array_push($array,$regid);
echo json_encode($array);
?>
的JSON應如下
["regid1","regid2", "regid3","regid4"]
然而,當我運行的代碼就序,以array_push 「regid5」 它給了我這個
[["regid1","regid2","regid3","regid4"],"regid5"]
和它的一個大難題
哇,我覺得很愚蠢 – silberbaum 2015-04-06 09:17:22
@harry_porter那麼,這是週一早上,至少我在哪裏;-) – jeroen 2015-04-06 09:18:48