我是新来的postgresql与PHP。我使用pg_fetch_array()函数获取下面的数组。从混合阵列中删除密钥,并重新编号
Array
(
[0] =>
[name] =>
[1] => 1
[status] => 1
[2] => C2005
[code] => C2005
)
除去指数1
和关键status
值之后,我不得不重新索引这个数组,这样预期的输出应该成为这样的:
Array
(
[0] =>
[name] =>
[1] => C2005
[code] => C2005
)
我试图
unset($row[1]);
unset($row['status'];
$foo = array_values($row);
echo "<pre>";
print_r($foo)
echo "</pre>";
,并得到输出
Array
(
[0] =>
[name] =>
[2] => C2005
[code] => C2005
)
在从数组中删除特定键后,数字索引如何重新编制索引?
使用'pg_fetch_assoc()''那么你就不会得到的数字索引列,它仅返回指定的列 – RiggsFolly
或者使用'pg_fetch_array($结果,NULL,PGSQL_ASSOC);'为了得到关联数组 – RiggsFolly
为什么你不仅在你的select语句中选择'name,code'? – hassan