我得到了这个数组结果:
Array
(
[0] => Array
(
[subscription_id] => 67
[user_id] => 156
[property_id] => 1036
[title] => Rotchild 50, Tel Aviv, Israel
[subscription_plan_id] => 13
[transactionID] => VHHDLY2P5CC7V5K34UA5SUFWVM
[transactionDisplayID] => 441486
[paid_with] => Visa
[active] => 1
[start_date] => 2015-02-11 09:22:08
[end_date] => 2015-03-12
[s_start_date] => 2015-02-12 09:29:33
[s_subscription_id] => 70
)
[1] => Array
(
[subscription_id] => 66
[user_id] => 156
[property_id] => 1036
[title] => Rotchild 50, Tel Aviv, Israel
[subscription_plan_id] => 2
[transactionID] => VHHDLY2P5CC7V5K34UA5SUFWVM
[transactionDisplayID] => 441486
[paid_with] => Visa
[active] => 1
[start_date] => 2015-02-11 09:22:07
[end_date] => 2015-03-12
[s_start_date] => 2015-02-12 09:26:50
[s_subscription_id] => 69
)
)
现在如何将end_date
键值替换为start_date
键值,并在1天内递增,如:
Array
(
[0] => Array
(
[subscription_id] => 67
[user_id] => 156
[property_id] => 1036
[title] => Rotchild 50, Tel Aviv, Israel
[subscription_plan_id] => 13
[transactionID] => VHHDLY2P5CC7V5K34UA5SUFWVM
[transactionDisplayID] => 441486
[paid_with] => Visa
[active] => 1
[start_date] => 2015-03-13
[end_date] => 2015-03-12
[s_start_date] => 2015-02-12 09:29:33
[s_subscription_id] => 70
)
[1] => Array
(
[subscription_id] => 66
[user_id] => 156
[property_id] => 1036
[title] => Rotchild 50, Tel Aviv, Israel
[subscription_plan_id] => 2
[transactionID] => VHHDLY2P5CC7V5K34UA5SUFWVM
[transactionDisplayID] => 441486
[paid_with] => Visa
[active] => 1
[start_date] => 2015-03-13
[end_date] => 2015-03-12
[s_start_date] => 2015-02-12 09:26:50
[s_subscription_id] => 69
)
)
任何想法如何将空间数组值替换为另一个?
答案 0 :(得分:1)
您正在查看嵌套的关联数组。如果您知道索引和键,那么它非常简单:
$endDate = str_replace('-', '/', your_array[0]['end_date']);
your_array[0]['start_date'] = date('Y-m-d', strtotime($endDate.'+1 days'));
$endDate = str_replace('-', '/', your_array[1]['end_date']);
your_array[1]['start_date'] = date('Y-m-d', strtotime($endDate.'+1 days'));
有关操纵日期/时间的更多详细信息,请查看strtotime和日期函数的手册。