How can negative and positive numbers be separated from an array in PHP and then output as separate arrays?

To separate negative and positive numbers from an array in PHP, you can iterate through the array and check each element's sign. You can then push the negative numbers into one array and the positive numbers into another array. Finally, you can output the two separate arrays.

<?php
// Input array
$numbers = [-2, 5, -8, 10, 3, -6, 7];

$positiveNumbers = [];
$negativeNumbers = [];

foreach ($numbers as $number) {
    if ($number < 0) {
        $negativeNumbers[] = $number;
    } else {
        $positiveNumbers[] = $number;
    }
}

// Output the separate arrays
echo "Negative Numbers: " . implode(", ", $negativeNumbers) . "\n";
echo "Positive Numbers: " . implode(", ", $positiveNumbers);
?>