说我有一个多维的,数字零索引数组,看起来像这样:从包含元素的键的值枚举多维PHP数组上的键最优雅的方式是什么?
$oldArray = (
0 => array("importantKey" => "1", "otherKey" => "someValue"),
1 => array("importantKey" => "4", "otherKey" => "someValue"),
);
什么是这个到下面最彻底的方法,只要我可以肯定“importantKey”
的独特性$newArray = (
1 => array("otherKey" => "someValue"),
4 => array("otherKey" => "someValue"),
);
的“importantKey”做一个GROUP BY子句后,从数据库检索多个行的时候,这是有用
使用foreach循环并枚举一个新数组对我来说是最明显的选择,但我想知道是否有一个PHP特定函数以更优雅的方式实现这一点。 – 2013-04-29 10:46:23
我会说最明显的选择!不要试图变聪明:-) – 2013-04-29 10:58:19