下面的代码用于使用我已经完成的swing将值推入firebase,但是现在我必须将其转换为php但是我正在转换我有php的firebase sdk但我不明白如何在该sdk中使用循环。 。?
final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = database.getReference();
DatabaseReference usersRef = ref.child(appName);
for (int i = 0; i < myList.size(); ++i) {
Map<String, Object> userUpdates = new HashMap<String, Object>();
String phone = myList.get(i);
System.out.println("mobile" + phone);
userUpdates.put("phoneNumber", phone);
userUpdates.put("sentMessage", false);
usersRef.child("contacts").child(mobile).push().updateChildren(userUpdates);
}
我的php实现如下..
for($i=0;$i<$length;$i++){
$arr = array("$mobile" =>array("phoneNumber"=>$myList($i), "sentMessage"=>false));
$data_string = json_encode($arr);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PATCH");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
echo $result = curl_exec($ch);
}
上面我的php实现是正确的。如果不是这里有什么问题?