为了账号安全,请及时绑定邮箱和手机立即绑定

Array_walk 值未显示

Array_walk 值未显示

PHP
慕工程0101907 2021-11-13 17:27:22
在获取 highlight_description 时遇到问题。我想回应highlights_title 和highlights_decription。这是数组{  "highlights_title": [    "Quiet Neighbourhood",    "Fabulous views",    "Great local community",    "Large play center in yard"  ],  "highlights_description": [    "Enjoy tranquil and relaxed atmosphere of the place",    "Get yourself surrounded by the stunning view opening",    "You will be delighted by the fantastic local community",    "Your kids will be happy having all these things around"  ]}这是我的代码,它只显示亮点标题。如何同时回显 highlighttitle 和 highlightdescription$data = "{"title":"Property Highlights","description":"Extensive upgrades and thorough maintenance have kept this home in prime condition. Hardwood floors and new carpets create a very comfortable living space.","content":"{\"highlights_title\":[\"Quiet Neighbourhood\",\"Fabulous views\",\"Great local community\",\"Large play center in yard\"],\"highlights_description\":[\"Enjoy tranquil and relaxed atmosphere of the place\",\"Get yourself surrounded by the stunning view opening\",\"You will be delighted by the fantastic local community\",\"Your kids will be happy having all these things around\"]}","module_tag":"div","bootstrap_size":"0","header_tag":"h3","header_class":"","style":"0"}"$highlights = json_decode($data, true);if(!empty($highlights)){    $content = $highlights['highlight_stitle'];    array_walk($content, function($value){        echo $value .'<br/>';    });}
查看完整描述

2 回答

?
神不在的星期二

TA贡献1963条经验 获得超6个赞

您可以通过这样的 foreach 一起扫描两个数组


if(!empty($highlights)) {

     foreach(array_map(null, $highlights['highlights_title'], $highlights['highlights_description']) 

              as list($title, $desc)) {

          echo $title.'\t'.$desc."<\br>\n";

     }

}


查看完整回答
反对 回复 2021-11-13
?
精慕HU

TA贡献1845条经验 获得超8个赞

您有第二个 json_encode 内容,因此:


$data = '{"title":"Property Highlights","description":"Extensive upgrades and thorough maintenance have kept this home in prime condition. Hardwood floors and new carpets create a very comfortable living space.","content":"{\"highlights_title\":[\"Quiet Neighbourhood\",\"Fabulous views\",\"Great local community\",\"Large play center in yard\"],\"highlights_description\":[\"Enjoy tranquil and relaxed atmosphere of the place\",\"Get yourself surrounded by the stunning view opening\",\"You will be delighted by the fantastic local community\",\"Your kids will be happy having all these things around\"]}","module_tag":"div","bootstrap_size":"0","header_tag":"h3","header_class":"","style":"0"}';

$highlights = json_decode($data, true);

var_dump($highlights);

if (!empty($highlights)) {

    $content = json_decode($highlights["content"], true);

    foreach($content as $subcontent){

       foreach($subcontent as $value){

          echo $value . "<br/>";

       }

    }    

}


查看完整回答
反对 回复 2021-11-13
  • 2 回答
  • 0 关注
  • 140 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号