[英]How to foreach and the inside is other foreach?
I want to display user names and the skills per user.我想显示用户名和每个用户的技能。 The user's display is works but skills are not working how to fix it?
用户显示正常但技能不工作如何解决?
index.php index.php
<?php
$jsondata = file_get_contents("data.json");
$json = json_decode($jsondata, true);
$output = "";
foreach ( $json['UserData'] as $display ) {
$output .="<p>" .$display['fname']. "</p>
</br>
<h6>Skills :</h6>";
foreach ( $json['skills'] as $value ) {
$output .=" <p>".$value."</p> </br>
";
}
}
echo $output;
?>
data.json数据.json
{
"UserData": [
{
"id": "name",
"fname": "Joey",
"lname": "Tulang",
"age": "29",
"gender": "Male",
"skills": [ "HTML", "CSS", "JavaScript" ],
"image": [ "html.jpg", "css.jpg", "js.jpg" ]
},
{
"id": "2",
"fname": "Angelica",
"lname": "Balce",
"age": "20",
"gender": "Female",
"skills": ["C++", "Python", "PHP"],
"image": [ "c++.jpg", "python.jpg", "php.jpg" ]
},
{
"id": "3",
"fname": "Mj",
"lname": "King",
"age": "21",
"gender": "male",
"skills": [ "Photoshop", "Figma", "Corel Draw"],
"image": [ "photoshop.jpg", "figma.jpg", "cdraw.jpg" ]
}
]
}
and I want to display it like this.我想像这样显示它。
Joey乔伊
Skills技能
Angelica当归
Skills技能
Mj米
Skills技能
You want to use foreach ( $display['skills'] as $value ) {
instead.您想使用
foreach ( $display['skills'] as $value ) {
代替。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.