【问题标题】:get last item in firebase array获取firebase数组中的最后一项
【发布时间】:2014-01-06 16:33:16
【问题描述】:

我正在使用 Firebase PHP 库,我想获取数组中的最后一项。

我试过了:

$todoPath = 'arcade/bonsai/gameInPlay/'.$userID.'/'.$gameID.'/'.$gamePlayID.'/scores/';
$response =$fb->get($todoPath);
 $json= json_decode($response, true);
 $last = end($json); 
 $scoreID=$last['name'];

我也试过了:

$todoPath = 'arcade/bonsai/gameInPlay/'.$userID.'/'.$gameID.'/'.$gamePlayID.'/scores/';
 $response =$fb->get($todoPath);
 $json= json_decode($response, true);
 $last = current(array_slice($json, -1));
 $scoreID=$last['name'];

这些都不行

【问题讨论】:

  • 发送var_dump($json) 看看里面到底有什么?

标签: php firebase


【解决方案1】:

你应该将指针移动到对象的末尾,然后获取最后一项的键。

// move pointer to end
end($json);

// get the key
$key = key($json);
var_dump($key);

如果这有帮助,请告诉我。

【讨论】:

    猜你喜欢
    • 2011-03-14
    • 1970-01-01
    • 2017-09-29
    • 1970-01-01
    • 2020-05-13
    • 1970-01-01
    • 1970-01-01
    • 2014-09-26
    相关资源
    最近更新 更多