How can a multidimensional array be created and accessed when using preg_match_all() in PHP?

When using preg_match_all() in PHP, the function returns a multidimensional array containing all matches found in a string. To access this multidimensional array, you can use nested loops to iterate through each level of the array. By using a combination of foreach loops and accessing array elements by their keys, you can easily navigate and retrieve the matched values from the multidimensional array.

// Example code to create and access a multidimensional array with preg_match_all()

// String to search for matches
$string = "Hello, my name is John Doe. I work at ABC Company.";

// Regular expression pattern to match words
$pattern = "/\b\w+\b/";

// Perform a global regular expression match
preg_match_all($pattern, $string, $matches);

// Access the multidimensional array of matches
foreach ($matches as $match) {
    foreach ($match as $value) {
        echo $value . "\n";
    }
}