“Globais PHP” Respostas de código

Função de variável global PHP

<?php
  $myVariable = "a";
  function changeVar($newVar) {
    global $myVariable
    $myVariable = "b";
  }
  echo $myVariable; // Should echo b
?>
Difficult Dugong

Como fazer uma variável PHP global

$a = 1;
$b = 2;
function Sum(){
    global $a, $b; // allows access to vars outside of function
    $b = $a + $b;
} 

Sum();
echo $b; // output is 3
Mushy Mink

Globais PHP

$GLOBALS["foo"]
JK

PHPCs globais

composer global require squizlabs/php_codesniffer
Puzzled Parrot

Respostas semelhantes a “Globais PHP”

Perguntas semelhantes a “Globais PHP”

Mais respostas relacionadas para “Globais PHP” em PHP

Procure respostas de código populares por idioma

Procurar outros idiomas de código