Can you provide a sample code snippet demonstrating how to separate negative and positive numbers from an array in PHP?

To separate negative and positive numbers from an array in PHP, you can iterate through the array and create two separate arrays - one for negative numbers and one for positive numbers. You can use a foreach loop to check each element in the array and push it to the appropriate array based on its sign.

<?php

// Input array containing both negative and positive numbers
$numbers = [-3, 5, -7, 10, 2, -8];

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

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

echo "Negative Numbers: " . implode(", ", $negativeNumbers) . "\n";
echo "Positive Numbers: " . implode(", ", $positiveNumbers) . "\n";

?>