php - 数组到字符串在cakephp中转换

标签 php mysql arrays cakephp

你好,我想在 cakephp 中将数组转换为字符串。这是我从表中检索数据的代码。

 $date_time_search=$this->Temptrip->find('all',array('fields'=>array('Temptrip.from_area as search'),'conditions'=>array('Temptrip.created >=' => $first1,'Temptrip.created <=' => $last2)));

$this->set('date_time_search', $date_time_search);

我的 .ctp 代码在这里- 我已经完全完成了我的输出作为数组作为数组

(
    [0] => Array
        (
            [Temptrip] => Array
                (
                    [search] => High Commission of Iran, Road No 75, Dhaka
                )

        )

但我希望我的输出与-[0] => 伊朗高级专员公署,75 号路,达卡

最佳答案

你可以这样试试。

use Cake\Utility\Hash;
...
...
$date_time_search=$this->Temptrip->find('all',array('fields'=>array('Temptrip.from_area as search'),'conditions'=>array('Temptrip.created >=' => $first1,'Temptrip.created <=' => $last2)));
$results = Hash::extract($date_time_search, '{n}.Temptrip.search');
$this->set('date_time_search', $results);

来源:Hash::extract

关于php - 数组到字符串在cakephp中转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36573431/

相关文章:

php - 如何确保页脚在打印时始终位于最后一页的底部?

php - 为什么我从 MySQL 查询中得到重复项?

sql - 根据查询将行插入 MySQL 表

JavaScript 未捕获类型错误 : Cannot read property of undefined

PHP 错误 in_array() [function.in-array] : Wrong datatype for second argument

php - Laravel Eloquent 为帖子创建类别

php - PHP 中的 undefined variable

php - 使用 PHP IMAP 打开电子邮件

c - 函数调用结束时的数组销毁

javascript - 在数组中查找子集组合