php global variable function
<?php
$myVariable = "a";
function changeVar($newVar) {
global $myVariable
$myVariable = "b";
}
echo $myVariable; // Should echo b
?>
php global variable function
<?php
$myVariable = "a";
function changeVar($newVar) {
global $myVariable
$myVariable = "b";
}
echo $myVariable; // Should echo b
?>
php set global variables from function
<?php
function setGlobalVariable() {
$GLOBALS['variable_name'] = "Some Value";
}
setGlobalVariable();
echo $variable_name;
// Outputs: Some Value
How to not use directly global variables in PHP
<?php
$search_html = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_SPECIAL_CHARS);
$search_url = filter_input(INPUT_GET, 'search', FILTER_SANITIZE_ENCODED);
echo "Vous avez recherché $search_html.\n";
echo "<a href='?search=$search_url'>Nouvelle recherche.</a>";
?>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us