Q:

Get variable from a function

I have two functions and i want to get a variable in the first function into the second one. My code is :
$adresse = array();

function first( $atts ) {

    global $adresse;
    $atts = shortcode_atts( 
        array(
            'url' => '',
        ),
        $atts
    );

    $adresse['url'] = $atts['url'];
    return $adresse['url'];

}

function second() {
    global $adresse;
    echo $adresse['url'];
 }

I want to get result of adresse in the second function.
Thanks for your help

A:

I would use class for this:
class Address {
    private $addresse;

    public function setUrl(string $url=''): void {
        $this->addresse['url'] = $url;
    }

    public function getUrl(): string {
        return $this->addresse['url'];
    }
}

And then use it like this:
$addr = new Address();
$atts = shortcode_atts( 
array(
  'url' => '',
), 
$atts
);

$addr->setUrl($atts['url']);

echo $addr->getUrl();

Details may change on your exact wish, ofc.

