Circularly shifting associative array?
associative-array, php
Solution
No looping required
$arr=array('Monday' => 'mon',
'Tuesday' => 'tue',
'Wednesday' => 'wed',
'Thursday' => 'thur',
'Friday' => 'fri',
'Saturday' => 'sat',
'Sunday' => 'sun');
//say your start is wednesday
$key = array_search("Wednesday",array_keys($arr));
$output1 = array_slice($arr, $key);
$output2 = array_slice($arr, 0,$key);
$new=array_merge($output1,$output2);
print_r($new);
Problem
Working in PHP, assume you have an associative array: ``` 'Monday' => 'mon' 'Tuesday' => 'tue' 'Wednesday' => 'wed' 'Thursday' => 'thur' 'Friday' => 'fri' 'Saturday' => 'sat' 'Sunday' => 'sun' ``` How could you perform a "circular" array shift? Say shifting things so that the array starts with Wednesday, and proceeds through all 7 days, ending with Tuesday? An important note: I need to do this by key, as I have other code determining what day the shift needs to start at.