我正在尋找一種方法來計算在搜索數據庫時所獲得的這些JSON字符串中返回的項目數量(以PHP爲單位)。在JSON請求中返回的項目數量的PHP數量?
原諒我,因爲我完全是廢話。
我被告知,因爲在JSON版本中沒有返回計數,就像在這個數據庫中的XML中一樣,我將不得不使用循環來計算結果數量?
我周圍看了一下,但似乎沒有適合我想做...
以下是字符串,我得到的一個例子:
Array (
[0] => stdClass Object (
[score] => 12
[popularity] => 3
[name] => Samantha Dark
[id] => 151019
[biography] => [url] => http://www.themoviedb.org/person/151019
[profile] => Array ()
[version] => 16
[last_modified_at] => 2011-04-11 17:17:33
)
[1] => stdClass Object (
[score] => 11
[popularity] => 3
[name] => Johnny Dark
[id] => 158737
[biography] => [url] => http://www.themoviedb.org/person/158737
[profile] => Array ()
[version] => 14
[last_modified_at] => 2011-04-11 17:18:38
)
)
及(如適用)這裏是我用來請求PHP &破譯它
$name = $_GET['search'];
$persons_result = $tmdb->searchPerson($name);
$persons = json_decode($persons_result);
foreach ($persons as $person) {
echo '<a href="tmdb_person.php?id='.$person->id.'">'.$person->name.'</a></br>';
}
是否有某種原因,['count'(HTTP: //php.net/manual/en/function.count.php)不起作用? – sdleihssirhc 2011-05-07 18:32:34