指定返回 $query->fetchArray()? 的键值?
使用 Doctrine,我正在执行类似这样的查询:
$query = Doctrine_Query::create()->select('id,name')->from('people');
return $query->fetchArray();
它返回一个类似于以下数组的对象:
array(3) {
[0]=>
array(4) {
["id"]=>
string(1) "34"
["name"]=>
string(7) "John"
}
[1]=>
array(4) {
["id"]=>
string(1) "156"
["name"]=>
string(6) "Bob"
}
[2]=>
array(4) {
["id"]=>
string(1) "27"
["name"]=>
string(7) "Alex"
}
}
注意数组的键如何从 0、1、2 等开始计数?我的问题:是否可以指定您想要的键值来自哪里?例如,我希望上述情况下的键值为 34、156,然后是 27。
我在 Doctrine 文档中注意到,两个 fetchArray()
都有您可以提供的参数,但它没有说明这些参数是什么...
public array fetchArray(string params)
http://www.doctrine-project.org/api/orm/1.2/doctrine/doctrine_query.html#fetchArray()
另外,我显然可以用首选的数组重新填充一个新数组键/值组合,但我试图避免所需的额外处理。
Using Doctrine, I'm doing a query kinda like this:
$query = Doctrine_Query::create()->select('id,name')->from('people');
return $query->fetchArray();
It returns an object similar to the following array of arrays:
array(3) {
[0]=>
array(4) {
["id"]=>
string(1) "34"
["name"]=>
string(7) "John"
}
[1]=>
array(4) {
["id"]=>
string(1) "156"
["name"]=>
string(6) "Bob"
}
[2]=>
array(4) {
["id"]=>
string(1) "27"
["name"]=>
string(7) "Alex"
}
}
Notice how the array's keys count up from 0, 1, 2, etc? My question: Is it possible to specify where you want the key values to come from? For example, I would like the key values in the above case to be 34, 156 and then 27.
I noticed in the Doctrine doc's that both fetchArray()
has parameters that you can feed them, but it doesn't say anything about what those parameters are...
public array fetchArray(string params)
http://www.doctrine-project.org/api/orm/1.2/doctrine/doctrine_query.html#fetchArray()
Also, I can obviously just repopulate a new array with the prefered key/value combinations, but I'm trying to avoid the extra processing required.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看 INDEXBY DQL 关键字。
尝试类似的方法:
Check out the INDEXBY DQL keyword.
Try something like: