Could you tell me a sorting algorithm for php array?

has an array.

$a=[
     ["id"=>1,name="w1"],
     ["id"=>4,name="w3"],
     ["id"=>3,name="w2"],
     ["id"=>5,name="w5"],
     ["id"=>6,name="w22"],
     ["id"=>8,name="w222"],
     ["id"=>30,name="w30"]
   ];

how did it become like this?

$a=[
     ["id"=>1, name="w1",  "sn"=>11],
     ["id"=>4, name="w3",  "sn"=>21],
     ["id"=>3, name="w2",  "sn"=>22],
     ["id"=>5, name="w5",  "sn"=>31],
     ["id"=>6, name="w22", "sn"=>32],
     ["id"=>8, name="w222","sn"=>33],
     ["id"=>30,name="w30", "sn"=>34]
   ];
The change of

sn begins with the power of 2 to the power of 0, and the change begins with the change of 2 to the power of 2 and 4 to 8. If there is any data below, it may be next time. 41,42,43,44,45,46,47,48 .

I can"t figure it out. It looks very simple. I don"t know how to start. It doesn"t matter how you write it. I"d like to ask a master to help me. Thank you!

sn comes in order, which is not convenient. Do not press id,name. In the present order.

May.11,2021

$a=[
 ['id'=>1,'name'=>'w1'],
 ['id'=>4,'name'=>'w3'],
 ['id'=>3,'name'=>'w2'],
 ['id'=>5,'name'=>'w5'],
 ['id'=>6,'name'=>'w22'],
 ['id'=>8,'name'=>'w222'],
 ['id'=>30,'name'=>'w30'],
 ['id'=>30,'name'=>'w30'],
 ['id'=>30,'name'=>'w30'],
 ['id'=>30,'name'=>'w30'],
 ['id'=>30,'name'=>'w30'],
 ['id'=>30,'name'=>'w30'],
 ['id'=>30,'name'=>'w30'],
   ];
function add_sn(&$arr){
    $len=count($arr);
   $j=0;
   $n=0;
   for ($i=1;$i<=pow(2,$n);$iPP) { 
        $arr[$j]['sn']=($n+1).$i;
        if($i==pow(2,$n)){
            $i=0;
            $nPP;
        }
        $jPP;
        if($j==$len){
            return;
        }
   }    
   }

   
   add_sn($a);
   print_r($a);
Menu