How can recursion be implemented in PHP for functions like find_all_links in the provided example code?

To implement recursion in PHP for functions like find_all_links, you can create a function that calls itself within its definition to traverse through nested arrays or structures. In the provided example code, you can modify the find_all_links function to check if the value is an array and recursively call itself to search for links within nested arrays.

function find_all_links($input) {
    $links = array();

    foreach ($input as $value) {
        if (is_array($value)) {
            $links = array_merge($links, find_all_links($value));
        } elseif (filter_var($value, FILTER_VALIDATE_URL)) {
            $links[] = $value;
        }
    }

    return $links;
}

// Example usage
$input = array("https://example.com", "https://example2.com", array("https://nested.com", "https://nested2.com"));
$all_links = find_all_links($input);

print_r($all_links);