mardi 10 décembre 2019

else if is not working in my php code , what should i do?

Hello guys i have a code that receive values from the another page and i want to check if the value equal with on of one values in the array then give me that value so this is my code :

**<?php
   session_start();
ob_start();
 //where we get data from the form
if (isset($_POST["btn"])){
    $name=$_POST["name"];
$number=$_POST["number"];
$date=$_POST["fd"].'/'. $_POST["sd"].'/' .$_POST["td"];
    echo $name;
    echo"</br>";
    echo $number;
    echo"</br>";
    echo $date;

    }
$ar=sscanf($date,"%d/%d/%d");

$month1=$ar[1]; // for example the value is 5

from the here i have array

$month=array(
    "juan"  =>"1",
    "feb"   =>"2",
    "march" =>"3",
    "april" =>"4",
    "may"   =>"5",
    "jun"   =>"6",
    "july"  =>"7",
    "agu"   =>"8",
    "sep"   =>"9",
    "oct"   =>"10",
    "nov"   =>"11",
    "dec"   =>"12"

);
function monthdate($m,$m1){

$flag=false;
foreach ($m1 as $key=>$val){

    $val1=$val;

    if ($val1 == $m){
    $flag=true;
      break;
    }

    else if(!$val1 == $m) {
    $flag=false;}

}
if($flag == true ){
    echo $val1;}

}
echo "your birthday month is ". monthdate($month1,$month);
echo"</br>";
?>**

why the function doesn't give me any data ?

Aucun commentaire:

Enregistrer un commentaire