只处理数组的日期


Handle only the dates of an array

如何只列出数组中的日期?

使用以下代码:

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
)

一种方法:

$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);
输出:

<>之前数组(7){[0] =>字符串(10)"2014-08-13"[1] =>字符串(10)"2014-08-13"[2] =>字符串(10)"2014-08-13"[3] =>字符串(10)"2014-08-13"[4] =>字符串(10)"2014-08-13"[5] =>字符串(10)"2014-08-13"[6] =>字符串(10)"2014-08-13"}之前

这里是Codepad demo

试试这个

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]);
}