7.3
April 2019
By Loïc Truchot
# php.ini
zend_extension=""
xdebug.default_enable=1
xdebug.auto_trace=1
xdebug.profiler_enable=1
VS
<script>
var test = 42;
function modifyTest () {
test = 24;
}
modifyTest()
console.log(test);
</script>
<?php
$test = 42;
function modifyTest () {
$test = 24;
}
modifyTest();
var_dump($test);
?>
Who will win ?
step 1
step 2
$test = 42;
function testX3 ($val) {
$result = $val * 3;
return $result;
}
$test = testX3($test);
step 3
$test = 42;
function testX4 () {
global $test;
$test = $test * 4;
}
testX4();
var_dump($test);
$test = 42;
function testX5 (&$var) {
$var = $var * 4;
}
testX5($test);
var_dump($test);
@see https://www.php.net/manual/fr/language.variables.superglobals.php
<form action="superglobales.php" method="POST">
Name: <input type="text" name="name" />
<input type="submit" />
</form>
step 1
function toQuizz($quizz, $rightIndex, $userChoice) {
if ($quizz[$rightIndex] == $userChoice) {
return "bravo";
} else {
return "error: right answer was" . $quizz[$rightIndex];
}
}
step 2
$("#btn").click(event => {
$.post({
url: "request.php",
data: { name: $("#ipt").val() },
success: data => alert(data)
});
});
<?php
$name = $_POST["name"];
echo "coucou $name !"
?>
<?php
$containTest = preg_match("/test/", "ceci est un test.");
var_dump($containTest);
?>
THANK'S EVERYONE
It's finally done ! See you soon
Next chapter : Oriented Object PHP...