将MySQL输出格式化为PHP数组

时间:2018-09-08 11:42:37

标签: php sql

我有这个查询:

$query = 'SELECT `trades`.`id` AS `trade.id` FROM `trades` WHERE `id` = '. $this->trade->id . ' ORDER BY `created_at` DESC LIMIT 1';

(当然)输出哪个

array(1) {
  ["trade.id"]=>
  string(2) "44"
}

如何获取它以代替输出?

array(1) {
  ["trade"]=> array(1) {
    ["id"]=> string(2) "44"
  }
}

1 个答案:

答案 0 :(得分:0)

$query = 'SELECT `trades`.`id` AS `id` FROM `trades` WHERE `id` = '. $this->trade->id . ' ORDER BY `created_at` DESC LIMIT 1';
$arr['trade']=$query;
print_r($arr);

检查它。我希望工作.....