دورة php للمبتدئين الدرس السابع
1- الشرط if ف php
//index.php
<?php
// $nom = 'samadi';
// echo $nom;
// $age = 20;
// echo $age;
// $note = 15.45;
// echo $note;
// $mineur = false;
// $majeur = true;
// $nom = "samadi";
// function getNom(){
// $nom = "alaoui";
// }
// $names = array('samadi','amine','hassan','adil');
// class Person{
// function Person(){
// return $this->nom = 'samadi';
// }
// }
// $person = new Person();
// echo $person->nom;
// $string = 'la vie est belle';
// echo strlen($string);
// $string = 'la vie est belle';
// echo strpos($string,'belle');
// $string = "la vie est belle";
// echo str_replace("la vie","ma fille",$string);
// define('NOM','samadi');
// echo NOM;
// $nom = 'samadi';
// echo $nom;
// $x = 18;
// $y = 8;
// echo $x*=$y;
// $x = 18;
// $y = 8;
// echo $x/=$y;
// $x = 8;
// $y = 8;
// if($x === $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x != $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x !== $y){
// echo 'oui';
// }
// $x = 8;
// echo $x++;
// echo ++$x;
//index.php
// $nom = 'samadi';
// echo $nom;
// $age = 20;
// echo $age;
// $note = 15.45;
// echo $note;
// $mineur = false;
// $majeur = true;
// $nom = "samadi";
// function getNom(){
// $nom = "alaoui";
// }
// $names = array('samadi','amine','hassan','adil');
// class Person{
// function Person(){
// return $this->nom = 'samadi';
// }
// }
// $person = new Person();
// echo $person->nom;
// $string = 'la vie est belle';
// echo strlen($string);
// $string = 'la vie est belle';
// echo strpos($string,'belle');
// $string = "la vie est belle";
// echo str_replace("la vie","ma fille",$string);
// define('NOM','samadi');
// echo NOM;
// $nom = 'samadi';
// echo $nom;
// $x = 18;
// $y = 8;
// echo $x*=$y;
// $x = 18;
// $y = 8;
// echo $x/=$y;
// $x = 8;
// $y = 8;
// if($x === $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x != $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x !== $y){
// echo 'oui';
// }
// $x = 8;
// echo $x--;
// echo --$x;
// $x = 8;
// $y = 8;
// if($x == 8 && $y == 8){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x == 8 || $y == 8){
// echo 'oui';
// }
// $x = true;
// if(!$x){
// echo 'oui';
// }
$x = 8;
if($x == 8){
echo 'oui';
}
?>
2- الشرط if else ف php
//index.php
<?php
// $nom = 'samadi';
// echo $nom;
// $age = 20;
// echo $age;
// $note = 15.45;
// echo $note;
// $mineur = false;
// $majeur = true;
// $nom = "samadi";
// function getNom(){
// $nom = "alaoui";
// }
// $names = array('samadi','amine','hassan','adil');
// class Person{
// function Person(){
// return $this->nom = 'samadi';
// }
// }
// $person = new Person();
// echo $person->nom;
// $string = 'la vie est belle';
// echo strlen($string);
// $string = 'la vie est belle';
// echo strpos($string,'belle');
// $string = "la vie est belle";
// echo str_replace("la vie","ma fille",$string);
// define('NOM','samadi');
// echo NOM;
// $nom = 'samadi';
// echo $nom;
// $x = 18;
// $y = 8;
// echo $x*=$y;
// $x = 18;
// $y = 8;
// echo $x/=$y;
// $x = 8;
// $y = 8;
// if($x === $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x != $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x !== $y){
// echo 'oui';
// }
// $x = 8;
// echo $x++;
// echo ++$x;
//index.php
// $nom = 'samadi';
// echo $nom;
// $age = 20;
// echo $age;
// $note = 15.45;
// echo $note;
// $mineur = false;
// $majeur = true;
// $nom = "samadi";
// function getNom(){
// $nom = "alaoui";
// }
// $names = array('samadi','amine','hassan','adil');
// class Person{
// function Person(){
// return $this->nom = 'samadi';
// }
// }
// $person = new Person();
// echo $person->nom;
// $string = 'la vie est belle';
// echo strlen($string);
// $string = 'la vie est belle';
// echo strpos($string,'belle');
// $string = "la vie est belle";
// echo str_replace("la vie","ma fille",$string);
// define('NOM','samadi');
// echo NOM;
// $nom = 'samadi';
// echo $nom;
// $x = 18;
// $y = 8;
// echo $x*=$y;
// $x = 18;
// $y = 8;
// echo $x/=$y;
// $x = 8;
// $y = 8;
// if($x === $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x != $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x !== $y){
// echo 'oui';
// }
// $x = 8;
// echo $x--;
// echo --$x;
// $x = 8;
// $y = 8;
// if($x == 8 && $y == 8){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x == 8 || $y == 8){
// echo 'oui';
// }
// $x = true;
// if(!$x){
// echo 'oui';
// }
$x = 8;
if($x == 8){
echo 'oui';
}else{
echo 'non';
}
?>
3- الشرط if elseif else ف php
//index.php
<?php
// $nom = 'samadi';
// echo $nom;
// $age = 20;
// echo $age;
// $note = 15.45;
// echo $note;
// $mineur = false;
// $majeur = true;
// $nom = "samadi";
// function getNom(){
// $nom = "alaoui";
// }
// $names = array('samadi','amine','hassan','adil');
// class Person{
// function Person(){
// return $this->nom = 'samadi';
// }
// }
// $person = new Person();
// echo $person->nom;
// $string = 'la vie est belle';
// echo strlen($string);
// $string = 'la vie est belle';
// echo strpos($string,'belle');
// $string = "la vie est belle";
// echo str_replace("la vie","ma fille",$string);
// define('NOM','samadi');
// echo NOM;
// $nom = 'samadi';
// echo $nom;
// $x = 18;
// $y = 8;
// echo $x*=$y;
// $x = 18;
// $y = 8;
// echo $x/=$y;
// $x = 8;
// $y = 8;
// if($x === $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x != $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x !== $y){
// echo 'oui';
// }
// $x = 8;
// echo $x++;
// echo ++$x;
//index.php
// $nom = 'samadi';
// echo $nom;
// $age = 20;
// echo $age;
// $note = 15.45;
// echo $note;
// $mineur = false;
// $majeur = true;
// $nom = "samadi";
// function getNom(){
// $nom = "alaoui";
// }
// $names = array('samadi','amine','hassan','adil');
// class Person{
// function Person(){
// return $this->nom = 'samadi';
// }
// }
// $person = new Person();
// echo $person->nom;
// $string = 'la vie est belle';
// echo strlen($string);
// $string = 'la vie est belle';
// echo strpos($string,'belle');
// $string = "la vie est belle";
// echo str_replace("la vie","ma fille",$string);
// define('NOM','samadi');
// echo NOM;
// $nom = 'samadi';
// echo $nom;
// $x = 18;
// $y = 8;
// echo $x*=$y;
// $x = 18;
// $y = 8;
// echo $x/=$y;
// $x = 8;
// $y = 8;
// if($x === $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x != $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x !== $y){
// echo 'oui';
// }
// $x = 8;
// echo $x--;
// echo --$x;
// $x = 8;
// $y = 8;
// if($x == 8 && $y == 8){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x == 8 || $y == 8){
// echo 'oui';
// }
// $x = true;
// if(!$x){
// echo 'oui';
// }
$x = 8;
if($x == 8){
echo 'oui';
}elseif($x == 6){
echo 6;
}else{
echo 'non';
}
?>
4- الشرط switch ف php
//index.php
<?php
// $nom = 'samadi';
// echo $nom;
// $age = 20;
// echo $age;
// $note = 15.45;
// echo $note;
// $mineur = false;
// $majeur = true;
// $nom = "samadi";
// function getNom(){
// $nom = "alaoui";
// }
// $names = array('samadi','amine','hassan','adil');
// class Person{
// function Person(){
// return $this->nom = 'samadi';
// }
// }
// $person = new Person();
// echo $person->nom;
// $string = 'la vie est belle';
// echo strlen($string);
// $string = 'la vie est belle';
// echo strpos($string,'belle');
// $string = "la vie est belle";
// echo str_replace("la vie","ma fille",$string);
// define('NOM','samadi');
// echo NOM;
// $nom = 'samadi';
// echo $nom;
// $x = 18;
// $y = 8;
// echo $x*=$y;
// $x = 18;
// $y = 8;
// echo $x/=$y;
// $x = 8;
// $y = 8;
// if($x === $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x != $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x !== $y){
// echo 'oui';
// }
// $x = 8;
// echo $x++;
// echo ++$x;
//index.php
// $nom = 'samadi';
// echo $nom;
// $age = 20;
// echo $age;
// $note = 15.45;
// echo $note;
// $mineur = false;
// $majeur = true;
// $nom = "samadi";
// function getNom(){
// $nom = "alaoui";
// }
// $names = array('samadi','amine','hassan','adil');
// class Person{
// function Person(){
// return $this->nom = 'samadi';
// }
// }
// $person = new Person();
// echo $person->nom;
// $string = 'la vie est belle';
// echo strlen($string);
// $string = 'la vie est belle';
// echo strpos($string,'belle');
// $string = "la vie est belle";
// echo str_replace("la vie","ma fille",$string);
// define('NOM','samadi');
// echo NOM;
// $nom = 'samadi';
// echo $nom;
// $x = 18;
// $y = 8;
// echo $x*=$y;
// $x = 18;
// $y = 8;
// echo $x/=$y;
// $x = 8;
// $y = 8;
// if($x === $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x != $y){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x !== $y){
// echo 'oui';
// }
// $x = 8;
// echo $x--;
// echo --$x;
// $x = 8;
// $y = 8;
// if($x == 8 && $y == 8){
// echo 'oui';
// }
// $x = 8;
// $y = 8;
// if($x == 8 || $y == 8){
// echo 'oui';
// }
// $x = true;
// if(!$x){
// echo 'oui';
// }
$x = 8;
// if($x == 8){
// echo 'oui';
// }elseif($x == 6){
// echo 6;
// }else{
// echo 'non';
// }
switch ($x) {
case 8:
echo 8;
break;
case 6:
echo 6;
break;
case 7:
echo 7;
break;
default:
echo "Aucun résultat";
}
?>