我正在寻找一种方法来计算在搜索数据库时得到的这些 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>';
}
Use the count http://www.php.net/manual/en/function.count.php功能于$persons
获取项目数量。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)