The best approach for this is to use a combination of tearing and reading files. Initially, the strategy is read as a whole line as a line. Then use explode to store the entire number in the array. However, in this case, the array will be a string array later, we can change the type of the array element from String to integer. Here is how
<?php
$_fp = fopen("php://stdin", "r");
fscanf($_fp, "%d\n", $count);
$numbers = explode(" ", trim(fgets($_fp)));
foreach ($numbers as &$number)
{
$number = intval($number);
}
sort($numbers);
?>
source
share