Variable permanent speichern in PHP

Submitted by Gast (nicht überprüft) on Di, 08/20/2019 - 15:19

So kann man Variable permanent (Laufzeit) speichern.

<?php


myvars( ["city"  => "bonn" ] );
myvars( ["alter" => "33" ] );
myvars( ["auto"  => "bmw" ] );

echo " Stadt: " . myvars("city");
echo " Alter: " . myvars("alter");
echo " Auto: " . myvars("auto");



function myvars( $arr ){
static $vars;

if( is_array($arr) ){
$key = key( $arr );
$vars[ $key ] = $arr[ $key];
} else {
return $vars[ $arr];
}

}

?>

 

Neuen Kommentar schreiben

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.