我试图从包含搜索关键词中的单词的json文件单词的关键字列表中显示,但数据inst显示,无法找出问题。
要显示的结果:
以下是代码:
JSON:
{
"list":[
{
"key":"Programmer PHP",
"value":"Programmer PHP"
},
{
"key":"Programmer JAVA",
"value":"Programmer JAVA"
},
{
"key":"Programmer C++",
"value":"Programmer C++"
}
]
}
PHP:
$q = "Programmer";
$url = 'what.json';
$content = file_get_contents($url);
$json = json_decode($content, true);
$count = 0;
foreach($json['list'] as $i){
echo "<li><a href=''>".strstr($i['value'],$q)."</a></li>";
$count++;
if($count >= 6){
break;
}
}