I have created an encryption algorithm in which I need to reverse, I need to separate a string into pairs of 3 into an array, I have looked all over and have found no help, how would I do this?
Edit: I have tried:
<?php
$todecode="#number too big to post#";
$len=strlen($todecode);
$a=0;
$b=array();
While($len!=$a){
//$decoded=chunk_split($todecode);
$add1=$todecode[$a];
$a=$a+1;
$add2=$todecode[$a];
$a=$a+1;
$add3=$todecode[$a];
$a=$a+1;
$adder=$add1,$add2,$add3;
array_push($b,$adder);
}
But nothing else yet.
$num_str = "12312312315234535";
print_r(str_split($num_str,3));
I don't know PHP, but I can provide a suggestion on what you must do.
First, you need to count the characters of your string, and create the 3 cell arrays you need:
ceil(19 / 3) = 7
arrays, or (better) a 7-by-3 arrayThen you'll need to store the chars on every row of the array:
i = -1; j=0;
for(j=0; j<length_of_your_string; j++) {
if (j % 3 == 0)
i++;
result_array[i][j % 3] = your_string.charAt(j);
}
I leave to you the translation to something you can use.