如何仅列出数组中的日期。
使用此代码:
do {
$integrantes[] = $row_rs['integrantes'];
} while ($row_rs = mysql_fetch_assoc($rs));
echo '<pre>';
print_r($integrantes);
echo '</pre>';
结果:
Array
(
[0] => 2:2014-08-13,4:2014-08-13,6:2014-08-13,7:2014-08-13
[1] => 3:2014-08-13,5:2014-08-13,6:2014-08-13
)
答案 0 :(得分:2)
一种方法:
$integrantes = array(
'2:2014-08-13,4:2014-08-13,6:2014-08-13,7:2014-08-13',
'3:2014-08-13,5:2014-08-13,6:2014-08-13'
);
$result = array();
foreach($integrantes as $delimited) {
$records = explode(',', $delimited);
foreach ($records as $record) {
list($id, $date) = explode(':', $record);
$result[] = $date;
}
}
var_dump($result);
输出:
array(7) { [0]=> string(10) "2014-08-13" [1]=> string(10) "2014-08-13" [2]=> string(10) "2014-08-13" [3]=> string(10) "2014-08-13" [4]=> string(10) "2014-08-13" [5]=> string(10) "2014-08-13" [6]=> string(10) "2014-08-13" }
这是 Codepad 演示
答案 1 :(得分:1)
试试这个
while ($row_rs = mysql_fetch_assoc($rs)){
preg_match_all('/\d{4}\-\d{2}-\d{2}/', $row_rs['integrantes'], $matches);
$integrantes = array_merge($integrantes, $matches[0]);
}