如何将变量拆分为2个变量?

So, I have a text box with a form. Where people can write thing in this specific order:

1:2
2:3
3:4
7:8

And it will get sended with POST to another .php file. There everything will be getted with $_POST['input']. But now I want the following thing: That it will get ordered. So from

1:2
2:3
3:4
7:8

to

$arg['1'] = 1;
$arg1['1'] = 2;
$arg['2'] = 2;
$arg1['2'] = 3;
$arg['3'] = 3;
$arg1['3'] = 4;
$arg['4'] = 7;
$arg1['4'] = 8;

How can I do this stuff? thanks!

What you need to do is:

  1. If there is a space breaking up each number:number, use the explode function to contain each one to an array.

  2. Create a foreach loop to deal with each number:number element in the array. You should use the explode function again to seperate the numbers each side of the comma.

     $input = "1:2 2:3 3:4 7:8";
    //Will put input into an array as array("1:2", "2:3" ...)
     $inputToArray = explode(" ", $input);
    
     $arg = array();
     $arg1 = array();
    
     $i = 1;
     foreach ($inputToArray as $element)
         {
    
         //Will turn element in array from 'number:number' into a new array 
         //(e.g array('1:1') will now be array(1, 1);
         $splitNumbers = explode(":", $element);
    
         $arg[$i] = $splitNumbers[0];
         $arg1[$i] = $splitNumbers[1];
    
        // To visibly show that it is working.
        echo "arg['$i'] : " . $arg[$i] . "<br>";
        echo "arg1['$i'] : " . $arg1[$i] . "<br>";
    
     $i++;
     }