拼接二维php数组
我有这个2d阵列,如果d超过30天,我喜欢拼接或取消设置a、b、c、d。 对php数组完全陌生,非常感谢您的帮助拼接二维php数组,php,arrays,Php,Arrays,我有这个2d阵列,如果d超过30天,我喜欢拼接或取消设置a、b、c、d。 对php数组完全陌生,非常感谢您的帮助 Array ( [0] => Array ( [0] => a [1] => b [2] => c [3] => d ) [1] => Array ( [0] => a
Array
(
[0] => Array (
[0] => a
[1] => b
[2] => c
[3] => d
)
[1] => Array (
[0] => a
[1] => b
[2] => c
[3] => d
)
)
foreach($arr as $a) {
if($a[3] + 30 < date) {
//???
}
}
数组
(
[0]=>阵列(
[0]=>a
[1] =>b
[2] =>c
[3] =>d
)
[1] =>阵列(
[0]=>a
[1] =>b
[2] =>c
[3] =>d
)
)
外汇($arr作为$a){
如果($a[3]+30<日期){
//???
}
}
foreach($arr as$index=>$a){
如果($a[3]+30<日期){
未结算($arr[$index]);
}
}
(而我,我自己,我会使用关联数组来更轻松地处理它,使其更易于阅读)foreach($arras$index=>$a){
如果($a[3]+30<日期){
未结算($arr[$index]);
}
}
(我、我自己和我会使用关联数组来处理它,使其更舒适,使人可读)下面是一个使用标准date_diff函数和DateTime对象的示例。date_diff还可以让您在除days之外的其他面额上有所不同。我通常更喜欢使用标准函数,因为它支持更多的情况,比如时区 --
下面是一个使用标准date_diff函数和DateTime对象的示例。date_diff还可以让您在除days之外的其他面额上有所不同。我通常更喜欢使用标准函数,因为它支持更多的情况,比如时区 --
您是在寻找unset函数?unset
a,b,c,d
还是从父数组中取消设置整个数组元素?您是在寻找unset函数?unseta,b,c,d
或从父数组中取消设置整个数组元素?如果要从要处理的数组中删除元素,我也会犹豫使用foreach。我忘了为什么。我越来越老了。如果要从正在进行foreach的数组中删除元素,我也会犹豫使用foreach。我忘了为什么。我老了。
foreach($arr as $index => $a) {
if($a[3] + 30 < date) {
unset($arr[$index]);
}
}
<?php
$d1=new DateTime("2016-03-22");
$d2=new DateTime("2015-03-23");
$d3=new DateTime("2015-03-24");
$d4=new DateTime("2015-03-25");
$today= new DateTime();
$arr = array(
array (
$d1,
$d2,
$d3,
$d4,
),
array (
$d4,
$d2,
$d3,
$d1
)
);
$count=0;
foreach ($arr as &$a) {
echo "Element" . $count . ": \r\n";
//print_r(date_diff($a[3], $today));
$difference = date_diff($a[3], $today);
if ($difference->days > 30 ){
echo "Removing. \r\n";
unset($arr[$count]);
}
else{
echo "Not removing. \r\n";
}
$count++;
}
print_r($arr);
?>
Element0: Removing.
Element1: Not removing.
// Array[0] is removed.
Array ( [1] => Array ( [0] => DateTime Object ( [date] => 2015-03-25 00:00:00 [timezone_type] => 3 [timezone] => America/New_York ) [1] => DateTime Object ( [date] => 2015-03-23 00:00:00 [timezone_type] => 3 [timezone] => America/New_York ) [2] => DateTime Object ( [date] => 2015-03-24 00:00:00 [timezone_type] => 3 [timezone] => America/New_York ) [3] => DateTime Object ( [date] => 2016-03-22 00:00:00 [timezone_type] => 3 [timezone] => America/New_York ) ) )