Need this php script to not have a function

Hello! This is a problem me and some other guy couldn’t figure out so i’m posting it here in hopes one of you can help out.

I need the script to not have a function. It seems the function is probably unnecessary and I’d like it to not have a function because it will be inside another function.

<?php
        $array = array('2004', 'March', 'January', '2006', 'chips', 'June', 'February', 'April', 'May', '1994', 'hotdogs');

        echo "<pre>". print_r($array, true) ."</pre>
";

        echo "Sorting...
";

        function is_month($var){
            $months = array('january', 'february', 'march', 'april',
                        'may', 'june', 'july', 'august', 'sepember',
                        'october', 'november', 'december');
            foreach($months as $month){
                if($month == strtolower($var)){
                    $p = 1;}
                }
                if($p == 1){return true;}
                else{return false;}
        }
        $month_array = array();
        $new_array = array();
        foreach($array as $key => $val){
        if(is_numeric($array[$key]) || !is_month($array[$key])){
        $new_array[] = $val;
        }
        else{
        $month_array[strtotime($val)] = $val; }
        
        }
        sort($new_array);
        ksort($month_array);

        
       foreach($new_array as $foo){
        echo "<pre>".$foo."</pre>";}
        echo "Months<br>";
        foreach($month_array as $foo){
        echo "<pre>".$foo."</pre>";}
        
?>

Obviously all you have to seemingly do is nest the foreach loop inside the other foreach loop. However, that ends in disastrous results. With certain variables showing up multiple times in the array.

Thanks for any help!