如何在PHP中的数组中打印以下字符串,只选择小写文本:
{"fieldValue":[{"portfoliocategory":"Printing","portfoliocategoryid":"printing"},{"portfoliocategory":"Digitization","portfoliocategoryid":"digitization"},{"portfoliocategory":"Android App","portfoliocategoryid":"androidapp"},{"portfoliocategory":"Photography","portfoliocategoryid":"photography"},{"portfoliocategory":"Artwork","portfoliocategoryid":"artwork"}],"fieldSettings":{"autoincrement":1}}
输出应为:
<ul>
<li>printing</li>
<li>digitization</li>
<li>androidapp</li>
<li>photography</li>
<li>artwork</li>
</ul>
感谢。
答案 0 :(得分:0)
据我了解你的问题。
$input = '{"fieldValue":[{"portfoliocategory":"Printing","portfoliocategoryid":"printing"},{"portfoliocategory":"Digitization","portfoliocategoryid":"digitization"},{"portfoliocategory":"Android App","portfoliocategoryid":"androidapp"},{"portfoliocategory":"Photography","portfoliocategoryid":"photography"},{"portfoliocategory":"Artwork","portfoliocategoryid":"artwork"}],"fieldSettings":{"autoincrement":1}}';
$output = '<ul>'; // Store the output
$values = json_decode($input); // This will convert to an object
foreach ($values->fieldValue as $val) {
$output .= '<li>'.$val->portfoliocategoryid.'</li>';
}
$output .= '</ul>';
$ output将为您提供预期的结果。