php to search a string : Hi im trying to use php to search a string and store certain elements in an array and then display the answers at the  end. Im trying to use the $match varaible but every i do i get an undefined error for it. my code is:

        <html>
        <head>
            <meta charset="UTF-8">
            <title>states</title>
        </head>
        <body>
            <?php
            $states = ('Mississippi Alabama Texas Massachusetts Kansas');
            $statesArray = [];
            
            //end in xas
            if (preg_match("/\b([a-zA-Z]*xas)\b/i", $states)) {
                $statesArray[0] = $match[1];
            }
    
            //begins with k ends in s. case sensitive comparison
            if (preg_match("/\b(K[[:alpha:]]*s$)\b/", $states)) {
                $statesArray[1] = $match[2];
            }
    
            // word start with m end in s
    //        if(preg_match("/M/[[:alpha:]]*s", $subject))
            if (preg_match("/\b(M[[:alpha:]]*s)\b/", $states)) {
                $statesArray[2] = $match[3];
            }
            //ends in a
            if (preg_match("/\b([a-zA-Z]*a)\b/i", $states)) {
                $statesArray[3] = $match[4];
            }
            //starts with m
            if (preg_match("/\b(M[[:alpha:]]+)\b/i", $states, $match)) {
                $statesArray[4] = $match[5];
            }
    
    
            $print = print($statesArray[0]);
            print($statesArray[1]);
            print($statesArray[2]);
            print($statesArray[3]);
            print($statesArray[4]);
            
            ?>
        </body>
    </html>

