【发布时间】:2020-06-06 13:23:56
【问题描述】:
假设我在 db user
下有数据{
"signup_login" : {
"2315218123" : {
"name" : "yohan",
},
"2665451854" : {
"name" : "Ram",
},
"5453698463" : {
"name" : "Raj",
}
}
}
因为我已经尝试过这段代码来检索数据库 user
下的 signup_login 的数据class lol {
protected $database;
protected $dbname = 'signup_login';
public function __construct(){
$acc = ServiceAccount::fromJsonFile(__DIR__ . '/secret/user-key.json');
$firebase = (new Factory)->withServiceAccount($acc)->create();
$this->database = $firebase->getDatabase();
}
public function get(){
if ($this->database->getReference($this->dbname)->getSnapshot()){
return $this->database->getReference($this->dbname)->getValue();
} else {
return FALSE;
}
}
}
$users = new lol();
var_dump($users->get());
因为我想以数组的形式存储数据,例如
$data = ["2315218123","2665451854","5453698463"]
但上面编写的代码将其作为正确的输出返回,但我想以上述数组的形式存储它,但我无法做到..
array(3) {
[2315218123]=>
array(1) {
["name"]=>
string(5) "yohan"
}
[2665451854]=>
array(1) {
["name"]=>
string(3) "Ram"
}
[5453698463]=>
array(1) {
["name"]=>
string(3) "Raj"
}
}
【问题讨论】:
标签: php json firebase firebase-realtime-database