$arrayfirst =
Array
(
[0] => 23:00-08:00
[1] => 23:00-08:00
[2] => 23:00-08:00
[3] => 23:00-08:00
[4] => 23:00-08:00
[5] => 00:00-00:00
[6] => 00:00-00:00
)
我想更换按键[0] [1] [2] [3] [4] [5] [6]
的值为
$arraysecond =
Array
(
[0] => Monday
[1] => Tuesday
[2] => Wedneday
[3] => Thursday
[4] => Friday
[5] => Saturday
[6] => Sunday
)
请帮忙。
答案 0 :(得分:4)
您可以使用array_combine
-
$new = array_combine($arraysecond, $arrayfirst);
$arraysecond
的值将是$arrayfirst
的键。
答案 1 :(得分:1)
$arrayfirst = array(
0 => '23:00-08:00',
1 => '23:00-08:00',
2 => '23:00-08:00',
3 => '23:00-08:00',
4 => '23:00-08:00',
5 => '00:00-00:00',
6 => '00:00-00:00',
);
$arraysecond = array(
0 => 'Monday',
1 => 'Tuesday',
2 => 'Wedneday',
3 => 'Thursday',
4 => 'Friday',
5 => 'Saturday',
6 => 'Sunday',
);
$new = array_combine($arraysecond, $arrayfirst);
echo '<pre>';
print_r($new);
echo '</pre>';
输出
Array
(
[Monday] => 23:00-08:00
[Tuesday] => 23:00-08:00
[Wedneday] => 23:00-08:00
[Thursday] => 23:00-08:00
[Friday] => 23:00-08:00
[Saturday] => 00:00-00:00
[Sunday] => 00:00-00:00
)
答案 2 :(得分:0)
使用:
解决它$result = array_combine($arraysecond, $arrayfirst);