TP5 an array of JSON objects into a normal array

Source: Internet
Author: User

From: 67671047

When using the TP5 framework to do projects, queries for data return objects, although they can also be traversed as normal arrays for subsequent processing, but this form is thrown directly to the front end or I want to temporarily add a data field to the returned result, and this JSON object array form is OK. Temporary data fields are not included in the object array, so converting to a normal array can be easier to handle.

<? PHP    Public function Scandata ()  {     = model ('datacount');      = $model all ();      return JSON ($DATA);  }  

After calling Sandata () in the same controller or class, we get an array of JSON objects, like this, if the front-end directly requests this method, the data in JSON format is obtained.

Processed into an ordinary array:

Method ①

= $ this , Jsondatacount ();   = Json_decode ($list->getcontent (),true);  

Method ②

$list = $ this

The results are similar to this after processing:

TP5 an array of JSON objects into a normal array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.