如何使用 PHP 在数组中按值进行循环排序


How to do cyclic order by value in an array with PHP?

>我有一个时区偏移量数组和一个当前时区偏移量。

    $offsets = array(-4,-5,-6,-7,-8,-9);
    $currentOff = -6; //user's timezone always change zone to zone

这是我需要的

    $result = array(-6,-7,-8,-9,-4,-5); 
    //ordering should start with the $currentOff.

我已经在 php 中浏览了一些数组引用,但无法做到。很高兴从你来到这里。

找到索引,对数组进行切片,合并切片:

$index = array_search($currentOff, $offsets);
$result = array_merge(array_slice($offsets, $index), array_slice($offsets, 0, $index));