Php得到季节选择

时间:2017-09-11 07:06:52

标签: php date

我在PHP中有一个四季数组。现在是秋天了。

[seasons] => Array
(
    [0] => Summer
    [1] => Autumn
    [2] => Winter
    [3] => Spring
)

我想通过以下方式排序。

[seasons] => Array
(
    [0] => Autumn 2017
    [1] => Winter 2017
    [2] => Spring 2018
    [3] => Summer 2018
)

我该怎么做?

1 个答案:

答案 0 :(得分:1)

$seasons = ['summer', 'autumn', 'winter', 'spring'];
$current_season = 'autumn';
$current_season_key = array_search($current_season, $seasons);
$seasons_temp = array_splice($seasons, $current_season_key);
$new_seasons = array_merge($seasons_temp, $seasons);
var_dump($new_seasons);

输出:

array(4) {
  [0]=>
  string(6) "autumn"
  [1]=>
  string(6) "winter"
  [2]=>
  string(6) "spring"
  [3]=>
  string(6) "summer"
}