Home > Backend Development > PHP Tutorial > PHP two-dimensional array conversion one-dimensional array

PHP two-dimensional array conversion one-dimensional array

WBOY
Release: 2016-07-06 13:52:07
Original
1020 people have browsed it

<code>

$data = array(1) {
  [0] => array(10) {
    ["account_id"] => string(1) "1"
    ["account_type"] => string(1) "1"
    ["account_phone"] => string(11) "18284573042"
    ["account_password"] => string(32) "33863f368f1195d4e14d357bcd4aac2b"
    ["account_salt"] => string(20) "acfhjzHIJVW2!#^)[+.;"
    ["account_alipay"] => string(1) "0"
    ["account_createtime"] => string(1) "0"
    ["account_cash"] => string(1) "0"
    ["account_name"] => string(9) "汪昌宁"
    ["account_isdelete"] => string(1) "0"
  }
}</code>
Copy after login
Copy after login

How to convert it into a one-dimensional array
I got this data using the select() method of thinkphp
How to convert it into a one-dimensional array
Or when querying this data Can I use other TP methods to get a one-dimensional array without using the select() method?

Reply content:

<code>

$data = array(1) {
  [0] => array(10) {
    ["account_id"] => string(1) "1"
    ["account_type"] => string(1) "1"
    ["account_phone"] => string(11) "18284573042"
    ["account_password"] => string(32) "33863f368f1195d4e14d357bcd4aac2b"
    ["account_salt"] => string(20) "acfhjzHIJVW2!#^)[+.;"
    ["account_alipay"] => string(1) "0"
    ["account_createtime"] => string(1) "0"
    ["account_cash"] => string(1) "0"
    ["account_name"] => string(9) "汪昌宁"
    ["account_isdelete"] => string(1) "0"
  }
}</code>
Copy after login
Copy after login

How to convert it into a one-dimensional array
I got this data using the select() method of thinkphp
How to convert it into a one-dimensional array
Or when querying this data Can I use other TP methods to get a one-dimensional array without using the select() method?

Get it directly

<code class="php">$data[0]</code>
Copy after login

ThinkPhp method

<code class="php">->first();</code>
Copy after login

But you can talk about your needs, for example, what is the only one you get? Or do you just want the first batch of information?

Use the find method in the model

You can use foreach to traverse it

Don’t use thinkphp’s select, that is for fetching multiple records, PHP executes it online

select() uses find() instead

Related labels:
php
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