<legend id='mcHoZ'><style id='mcHoZ'><dir id='mcHoZ'><q id='mcHoZ'></q></dir></style></legend>
    <bdo id='mcHoZ'></bdo><ul id='mcHoZ'></ul>
<i id='mcHoZ'><tr id='mcHoZ'><dt id='mcHoZ'><q id='mcHoZ'><span id='mcHoZ'><b id='mcHoZ'><form id='mcHoZ'><ins id='mcHoZ'></ins><ul id='mcHoZ'></ul><sub id='mcHoZ'></sub></form><legend id='mcHoZ'></legend><bdo id='mcHoZ'><pre id='mcHoZ'><center id='mcHoZ'></center></pre></bdo></b><th id='mcHoZ'></th></span></q></dt></tr></i><div id='mcHoZ'><tfoot id='mcHoZ'></tfoot><dl id='mcHoZ'><fieldset id='mcHoZ'></fieldset></dl></div>

<small id='mcHoZ'></small><noframes id='mcHoZ'>

      1. <tfoot id='mcHoZ'></tfoot>

        如何得到一维标量数组作为dql查询结果?

        How to get a one-dimensional scalar array as a doctrine dql query result?(如何得到一维标量数组作为dql查询结果?)
        <i id='Biot7'><tr id='Biot7'><dt id='Biot7'><q id='Biot7'><span id='Biot7'><b id='Biot7'><form id='Biot7'><ins id='Biot7'></ins><ul id='Biot7'></ul><sub id='Biot7'></sub></form><legend id='Biot7'></legend><bdo id='Biot7'><pre id='Biot7'><center id='Biot7'></center></pre></bdo></b><th id='Biot7'></th></span></q></dt></tr></i><div id='Biot7'><tfoot id='Biot7'></tfoot><dl id='Biot7'><fieldset id='Biot7'></fieldset></dl></div>

            <small id='Biot7'></small><noframes id='Biot7'>

              • <legend id='Biot7'><style id='Biot7'><dir id='Biot7'><q id='Biot7'></q></dir></style></legend>

                <tfoot id='Biot7'></tfoot>

                  <tbody id='Biot7'></tbody>
                  <bdo id='Biot7'></bdo><ul id='Biot7'></ul>

                  本文介绍了如何得到一维标量数组作为dql查询结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想从 Auction 表的 id 列中获取一组值.如果这是一个原始 SQL,我会写:

                  从拍卖中选择id

                  但是当我在 Doctrine 中这样做并执行时:

                  $em->createQuery("SELECT a.id FROM Auction a")->getScalarResult();

                  我得到一个这样的数组:

                  数组(数组('id' => 1),数组('id' => 2),)

                  相反,我想要一个这样的数组:

                  数组(1、2)

                  我如何使用 Doctrine 做到这一点?

                  解决方案

                  PHP

                  5.5

                  您可以使用 array_map,并且由于每个数组只有一个项目,因此您可以优雅地使用'current' 作为回调,而不是写一个 闭包.

                  $result = $em->createQuery("SELECT a.id FROM Auction a")->getScalarResult();$ids = array_map('current', $result);

                  <块引用>

                  有关内存使用的其他信息,请参阅Petr Sobotka 在下面的回答.

                  PHP >= 5.5

                  作为 jcbwlkr 在下面的回答,推荐使用 array_column 的方式.

                  I want to get an array of values from the id column of the Auction table. If this was a raw SQL I would write:

                  SELECT id FROM auction
                  

                  But when I do this in Doctrine and execute:

                  $em->createQuery("SELECT a.id FROM Auction a")->getScalarResult(); 
                  

                  I get an array like this:

                  array(
                      array('id' => 1),
                      array('id' => 2),
                  )
                  

                  Instead, i'd like to get an array like this:

                  array(
                      1,
                      2
                  )
                  

                  How can I do that using Doctrine?

                  解决方案

                  PHP < 5.5

                  You can use array_map, and since you only have on item per array, you can elegantly use 'current' as callback, instead of writing a closure.

                  $result = $em->createQuery("SELECT a.id FROM Auction a")->getScalarResult();
                  $ids = array_map('current', $result);
                  

                  See Petr Sobotka's answer below for additional info regarding memory usage.

                  PHP >= 5.5

                  As jcbwlkr's answered below, the recommended way it to use array_column.

                  这篇关于如何得到一维标量数组作为dql查询结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                • <tfoot id='ADC8E'></tfoot>
                • <i id='ADC8E'><tr id='ADC8E'><dt id='ADC8E'><q id='ADC8E'><span id='ADC8E'><b id='ADC8E'><form id='ADC8E'><ins id='ADC8E'></ins><ul id='ADC8E'></ul><sub id='ADC8E'></sub></form><legend id='ADC8E'></legend><bdo id='ADC8E'><pre id='ADC8E'><center id='ADC8E'></center></pre></bdo></b><th id='ADC8E'></th></span></q></dt></tr></i><div id='ADC8E'><tfoot id='ADC8E'></tfoot><dl id='ADC8E'><fieldset id='ADC8E'></fieldset></dl></div>

                      <legend id='ADC8E'><style id='ADC8E'><dir id='ADC8E'><q id='ADC8E'></q></dir></style></legend>

                        <small id='ADC8E'></small><noframes id='ADC8E'>

                          <tbody id='ADC8E'></tbody>
                            <bdo id='ADC8E'></bdo><ul id='ADC8E'></ul>