【发布时间】:2014-02-27 20:00:57
【问题描述】:
我正在尝试将我的数组分解为如下所示:
[0] => Array
(
[0] => 14 // this is hours
[1] => 38 // this is minutes
[2] => 14 // this is hours again
[3] => 59 // this is minutes again
)
[1] => Array
(
[0] => 15 // this is hours
[1] => 10 // this is minutes
[2] => 16 // this is hours again
[3] => 40 // this is minutes again
)
.
.
.
[200] => Array
(
[0] => 13 // this is hours
[1] => 35 // this is minutes
[2] => 23 // this is hours again
[3] => 32 // this is minutes again
)
这是因为我以后会比较这些时间。
我有这样的时间列表:
15:48,16:10 12:01,12:19 13:06,13:28 10:45,11:02
现在我把它放在一个看起来像这样的数组中:
[0] => 16:10,16:36
[1] => 13:06,13:17
.
.
.
[200] => 14:38,14:59
到目前为止我已经尝试过什么
$length = count($timesArr);
for($i=0; $i < $length; $i++){
foreach (explode(',', $timesArr[$i]) as $piece) {
$timesArray[] = explode(':', $piece);
}
}
这很接近,因为结果输出是这样的:
[0] => Array
(
[0] => 14
[1] => 38
)
[1] => Array
(
[0] => 14
[1] => 59
)
所以主要问题是我需要如上所示的单元格 0 和 1 位于同一个单元格中
我也可以直接从字符串开始,所以我会爆炸字符串。
【问题讨论】:
-
您可以使用带有
preg_replace_callback()的正则表达式来处理它
标签: php arrays multidimensional-array explode