PHP scheduling problem, look at the picture

A company had no idea after thinking about the interview questions for half an hour.

$arr = [
    [4, 5, 9, 4, 1],
    [11, 14, 9, 6, 20],
    [21, 44, 90, 16, 21],
    [16, 34, 99, 600, 230],
    [121, 18, 89, 60, 33]
]

the array $arr [0] [0] is the maximum, $arr [4] [4] is the second largest, $arr [0] [1] is the third largest, and so on, $arr [2] [2] is the minimum

.

4,33,5,60,90

006tNbRwly1fwx7gs4yxmj31hc0u0kjc.jpg

Oct.26,2021

$arr = [
    [4, 5, 9, 4, 1],
    [11, 14, 9, 6, 20],
    [21, 44, 90, 16, 21],
    [16, 34, 99, 600, 230],
    [121, 18, 89, 60, 33]
]

$arr1 = [];
foreach ($arr as $v) {
    $arr1 = array_merge($arr1, $v);
}

rsort($arr1);

$arrA = [];
$arrB = [];

foreach ($arr1 as $key => $value) {
    if ($key % 2 == 0) {
        $arrA[] = $value;
    } else {
        array_unshift($arrB, $value);
    }
}

$arrC = array_merge($arrA, $arrB);

return array_chunk($arrC, 5);

$arr = [
    [4, 5, 9, 4, 1],
    [11, 14, 9, 6, 20],
    [21, 44, 90, 16, 21],
    [16, 34, 99, 600, 230],
    [121, 18, 89, 60, 33]
];

foreach ($arr as &$v) {
    rsort($v);
    $l = $r = [];
    foreach ($v as $key => $value) {
        if ($key & 1) {
            array_unshift($r, $value);
        } else {
            $l[] = $value;
        }
    }
    $v = array_merge($l, $r);
}
var_dump($arr);

made some changes based on @ Masterton


I don't know if this is the case

$arr = [
    [4, 5, 9, 4, 1],
    [11, 14, 9, 6, 20],
    [21, 44, 90, 16, 21],
    [16, 34, 99, 600, 230],
    [121, 18, 89, 60, 33]
];
$result = array_reduce($arr, 'array_merge', array());
$count=count($result);
for($i=0;$i<$count;$iPP){
    if($i%2==0){
        $arrs[]+=$result[$i/2];
    }else{
        $arrs[]+=$result[$count-1-floor($i/2)];
    }
}
print_r($arrs);
  • Jquery sortable

    want to compare my use of jquery sortable I want to compare if A B C D E if B is moved to D , it is only to Bauddline An and E that they are not sent to php for processing . how do I do this? ...

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bd029f-2fa1e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bd029f-2fa1e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?