Formation PHP 5 et MySQL Cours 10 : La portée des variables

Tendance

Télévision & IPTV

- Advertisement -

[su_youtube url= »https://www.youtube.com/watch?v=w9u-0_eX5ls »]

Code 1

<?php

- Advertisement -

$a =10;

function test(){

echo « afficher la variable en interne ».$a. »<br> »;

- Advertisement -

}

echo « afficher la variable en externe « .$a. »<br> »;

test();

Code 2

- Advertisement -

<?php

$a =10;

function test(){

global $a;

echo « afficher la variable en interne ».$a. »<br> »;

}

echo « afficher la variable en externe « .$a. »<br> »;

test();

?>

Code 3

<?php

function test(){

$a =10;

echo « afficher la variable en interne ».$a. »<br> »;

}

echo « avant l’execution de la fonction « .$a. »<br> »;

test();

echo « après l’execution de la fonction « .$a. »<br> »;

?>

Code 4

<?php

function test(){

static $a =20;

echo « \$a= ».$a. »<br> »;

$a++;

}

test ();

test ();

test ();

?>

Derniers articles

Crise maroco-tunisienne : l’ombre du Sahara sur deux nations sœurs

Depuis août 2022, le Maroc et la Tunisie traversent une crise diplomatique inédite, née d’un incident en apparence protocolaire....

Plus d'articles