How to convert json object to array in thinkphp5 (code)

不言
Release: 2023-04-03 15:36:01
Original
11729 people have browsed it

The content of this article is about how to convert json objects into arrays (code) in thinkphp5. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1. Initially we use the following code to output:

The above code will output the following json object:

.

If we want to output on the page, we must convert it into an array:

  $list = json_decode($list->getContent(),true);
  $this->assign('data',$list['data']);
  return $this->fetch('tea');
Copy after login

In this way, we can convert the json object into an array, and take out the data array in $list, and then We use the volist tag to loop the output in the front desk:

{volist name="data" id="it"}
                <a href="{:url(&#39;index/index/test&#39;)}?teacherid={$it.teacherid}" class="weui-media-box weui-media-box_appmsg">       
                  <div class="weui-media-box__hd" >
                    <img class="weui-media-box__thumb" src="../../../public/static/images/cat.jpg" alt="">
                  </div>
                  <div class="weui-media-box__bd" >
                    <h4 class="weui-media-box__title">教师:{$it.teachername}</h4>
                    <p class="weui-media-box__desc">任课:{$it.course}</p>
                  </div>
                </a>
{/volist}
Copy after login

In this way, our front desk page comes out:

Recommended related articles:

How to check whether a remote file exists in php (pure code)

Code example of how to delete a directory and all files in the directory

The above is the detailed content of How to convert json object to array in thinkphp5 (code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template