Bases du langage
|
Ouverture de contexte PHP
|
<?php |
|
Fermeture de contexte PHP
|
?> |
|
Commentaire (ligne simple)
|
// Texte |
|
Commentaire (multiligne)
|
/* Texte */ |
|
Fin d'instruction
|
; |
|
Bloc d'instructions
|
{ instruction; } |
|
bool
|
|
int
|
|
float
|
|
string
|
|
array
|
|
object
|
|
resource
|
|
null
|
|
Initialisation
|
$variable = 'valeur'; |
|
Test valeur vide
|
empty($variable); |
|
Test d'existence
|
isset($variable); |
|
Destruction
|
unset($variable); |
|
Initialisation
|
define('NOM', 'valeur');const NOM = 'valeur'; |
|
Utilisation
|
echo NOM; |
|
Test d’existence
|
defined(NOM); |
|
Inversion
|
!true |
|
ET logique
|
AND && |
|
OU logique
|
OR || |
|
OU exclusif logique
|
XOR |
|
Priorités forcées
|
( test booléen ) |
|
Adition
|
1 + 2 |
|
Soustraction
|
1 - 2 |
|
Multiplication
|
1 * 2 |
|
Division
|
1 / 2 |
|
Modulo
|
1 % 2 |
|
Incrémentation
|
$nombre++ |
|
Décrémentation
|
$nombre-- |
|
Augmentation
|
$nombre += $valeur; |
|
Diminution
|
$nombre -= $valeur; |
|
Initialisation large
|
"phrase" |
|
Initialisation stricte
|
'phrase' |
|
Encapsulation
|
"Phrase n°$numero !" |
|
Contaténation
|
'Phrase n°' |
|
Recherche
|
strpos()strrpos() |
|
Extraction
|
substr() |
|
Déclaration
|
$tableau = array(); |
|
Tab. numérique
auto |
$nombres = [1, 9]; |
|
Tab. numérique
fixe |
$nombres = [ |
|
Tab. associatif
|
$client = [ |
|
Ajout auto d’élt
|
$nombres[] = 11; |
|
Test d'existence
|
isset($client['nom']) array_key_exists()in_array() |
|
Accès au contenu
associatif |
echo $client['nom']; |
|
Accès au contenu
numérique |
foreach ($nombres as $n) { |
|
Modification d’élt
|
$client['nom'] = 'B.'; |
|
Effacement d’élt
|
unset($client['nom']); |
/**
* @param array $chanson
* @param int $nombreDeFois
* @return bool True si on a pu tout chanter.
*/
function chanter($chanson, $nombreDeFois = 1)
{
// On chante
return true;
}
$connexion = mysqli_connect(
$hote,
$compteMysql,
$motDePasseMysql,
$baseDeDonnees
);
if (!$connexion) {
http_response_code(500);
die('Erreur de connexion');
}
if ($res = mysqli_query($connexion, $sql)) {
while ($valeurs = mysqli_fetch_assoc($res)) {
var_dump($valeurs);
}
mysqli_free_result($res);
}
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.