0

次のような特定の mysql テーブルからのデータを含む多次元配列があるとします。

Array ( [0] => Array ( [0] => 5255071 [id] => 5255071 [1] => 2013-02-28 20:40:48 [sent] => 2013-02-28 20:40:48 ) [1] => Array ( [0] => 5253758 [id] => 5253758 [1] => 2010-11-16 12:56:39 [sent] => 2010-11-16 12:56:39 ) [2] => Array ( [0] => 5253517 [id] => 5253517 [1] => 2010-11-16 12:43:57 [sent] => 2010-11-16 12:43:57 ) [3] => Array ( [0] => 5252348 [id] => 5252348 [1] => 2010-11-16 11:19:35 [sent] => 2010-11-16 11:19:35 ) [4] => Array ( [0] => 5252343 [id] => 5252343 [1] => 2010-11-16 11:19:01 [sent] => 2010-11-16 11:19:01 ) [5] => Array ( [0] => 5252254 [id] => 5252254 [1] => 2010-11-16 11:11:26 [sent] => 2010-11-16 11:11:26 ) [6] => Array ( [0] => 5251390 [id] => 5251390 [1] => 2010-11-16 09:16:57 [sent] => 2010-11-16 09:16:57 ) [7] => Array ( [0] => 5249381 [id] => 5249381 [1] => 2010-11-16 03:01:32 [sent] => 2010-11-16 03:01:32 ) [8] => Array ( [0] => 5249086 [id] => 5249086 [1] => 2010-11-16 02:47:30 [sent] => 2010-11-16 02:47:30 ) [9] => Array ( [0] => 5247987 [id] => 5247987 [1] => 2010-11-16 01:59:34 [sent] => 2010-11-16 01:59:34 ) [10] => Array ( [0] => 5247325 [id] => 5247325 [1] => 2010-11-16 01:33:12 [sent] => 2010-11-16 01:33:12 ) ) 

「id」値のみを含む新しい単一の配列を作成する方法はありますか? これは:

array(5255071, 5253758, 5253517, 5252348, ...)

アイデアは、foreach ループの使用を避けることです。前もって感謝します。

4

2 に答える 2

3

これに使用できますarray_map()

function extractId ($array) { return $array['id']; }
$targetArray = array_map($sourceArray, "extractId");
于 2013-03-01T15:01:16.817 に答える
1
$output = array_values($array['id']);

参照: array_values

于 2013-03-01T15:00:21.163 に答える