Move rule WebProxy

Hello community,

I came across a problem and I’m not
able to solve.
It is as follows:

I have rules in my WebProxy (note picture below):
Selection_001.png
I want to move the first rule for the last position in this list, and I can not.

The information loaded in the table are found in Mikrotik,
according to the code below:

$API ->write("/ip/proxy/access/print");
		$ler = $API ->read(false);
		$array = $API ->parse_response($ler);

		//imprimir array de sites cadastrados
		$length = count($array);
		//print_r($array);

		echo "
		 <table border='1' cellspacing='2' summary='Tabela de dados mikrotik'>
		  <caption><h2><b>Dados Proxy</b></h2></caption>

		  ...

		<tbody>";
			for ($i = 0; $i < $length; $i++){
		
			$primeiro = $array[$i];

			echo "<tr>";
			echo "<td>".($i + 1)."</td>";
			echo "<td>" .$primeiro['dst-host']."</td>";
			echo "<td>" .$primeiro['hits']. "</td>";
			echo "<td>" .$primeiro['disabled']. "</td>";
			echo "<td>" .$primeiro['comment']. "</td>";

			//tratando palavra que vem do mikrotik
			if($primeiro['action'] == "true"){

				echo "<td><font color='red'>deny</font></td>";

			}//fim if deny
			else {
				echo "<td><font color='green'>allow</font></td>";
			}//fim do else

                        ...

			}//fim do for
			echo "</tbory>";
			echo "</table>";

When I try to move the rule, the payoff is that there is no index reported:

Notice: Undefined index: 10 in /var/www/html/moverRegraProxy.php on line 59

the code to move the rule is the following:

...

$ori = $_POST['idOri'];
$dest = $_POST['idDest'];

//
$ori = $ori - 1;
if($ori >= $dest){

	$dest = $dest -1;

}

moverRegra($ori, $dest);


//função para mover
function moverRegra($ori, $dest){

	...

	if($API ->connect($ipMik, $login, $senha)){

	$API ->write("/ip/proxy/access/print");
	$array = $API ->read();

	//pegando id da  primeira regra
	$linha = $array[$ori];
	$id1 = $linha[".id"];

	//verificando o tamanho do array
	$length = count($array);
	

	if($dest == $length){

	//$dest = $dest + 1;

}//fim do if

	//pegando id da segunda regra
	$linha2 = $array[$dest];
	$id2 = $linha2['.id'];

	$API ->write("/ip/proxy/access/move", false);
	$API ->write("=numbers=$id1", false);
	$API ->write("=destination=$id2");

	$leu = $API ->read(false);
	$array = $API ->parse_response($leu);		

		$API ->disconnect();

	}//fim do if

        ...

}//fim da função moverRegra

I’ve tried several ways, and no success. What do you say to me?
I realize that adding a time to print the column ‘ID’. But treat it in a decreasing time to move the rule.

Thanks in advance.

Note: omit sections of code so that the post would not be so great #8).