左上角文件——首选项——设置——输入php.validate.executablePath
{
"workbench.colorTheme": "Default Dark Modern",
"php.validate.executablePath": "E:/phpstudy/php.exe",
"php.debug.executablePath": "E:/phpstudy/php.exe",
"phpserver.phpConfigPath": "E:/phpstudy/php.ini",
"phpserver.phpPath": "E:/phpstudy/php.exe"
}
代码:
<?php
$data = '{
"hbt": "0",
"hbt2": "2",
"hbt3": "3"
}';
// 将JSON字符串转换为关联数组
$array = json_decode($data, true);
// 遍历数组并筛选出值不为0的对象
$result = array();
foreach ($array as $key => $value) {
if ($value != "0") {
$result[$key] = $value;
}
}
// 输出结果
foreach ($result as $key => $value) {
echo $key . ": " . $value . "\n";
}
这样代表运行成功