Home  >  Article  >  Backend Development  >  PHP 二维数组转换一维数组

PHP 二维数组转换一维数组

WBOY
WBOYOriginal
2016-07-06 13:52:07963browse

<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>

如何转换成一维数组
这条数据我是用thinkphp 的select()方法得到的
用什么方法把他转换成一维数组
或是在查询出这条数据的时候不用select()方法可以用其他TP方法得到一维数组么?

回复内容:

<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>

如何转换成一维数组
这条数据我是用thinkphp 的select()方法得到的
用什么方法把他转换成一维数组
或是在查询出这条数据的时候不用select()方法可以用其他TP方法得到一维数组么?

直接拿

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

ThinkPhp 方法

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

不過你可以說說看你的需求,例如說你取得的是唯一?還是說只想一堆資料的第一筆?

用模型中的find方法

可以用foreach遍历一下

不要用thinkphp的select,那个是取多条记录用的,PHP在线执行

select()改用find()

Statement:
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