开发者

php function echo

I have:

$an = "1989";
$luna = "4";
$zi = "23";


function CalzulareZodie($date){
         list($an,$开发者_如何学JAVAluna,$zi)=explode("-",$date);
         if(($luna==1 && $day>20)||($month==2 && $zi<20)){
              return "Varsator";
         }else if(($luna==2 && $zi>18 )||($luna==3 && $zi<21)){
              return "Pesti";
         }else if(($luna==3 && $zi>20)||($luna==4 && $zi<21)){
              return "Berbec";
         }else if(($luna==4 && $zi>20)||($luna==5 && $zi<22)){
              return "Taur";
         }else if(($luna==5 && $zi>21)||($luna==6 && $zi<22)){
              return "Gemeni";
         }else if(($luna==6 && $zi>21)||($luna==7 && $zi<24)){
              return "Rac";
         }else if(($luna==7 && $zi>23)||($luna==8 && $zi<24)){
              return "Leu";
         }else if(($luna==8 && $zi>23)||($luna==9 && $zi<24)){
              return "Fecioara";
         }else if(($luna==9 && $zi>23)||($luna==10 && $zi<24)){
              return "Balanta";
         }else if(($luna==10 && $zi>23)||($luna==11 && $zi<23)){
              return "Scorpion";
         }else if(($luna==11 && $zi>22)||($luna==12 && $zi<23)){
              return "Sagetator";
         }else if(($luna==12 && $zi>22)||($luna==1 && $zi<21)){
              return "Capricorn";
         }
    }

how can i echo the result of this function?

i've tried with:

$zodia=CalculareZodie();
echo "Zodia este: ".$zodia;  

What is wrong?


Your function takes an argument. You are not passing one.

$zodia=CalculareZodie($somedate);

You've also misspelled it.


You forgot to pass argument. Also check the spelling CalzulareZodie

$zodia= CalzulareZodie('1989-4-23');
echo "Zodia este: ".$zodia; 


You should pass the date as function's argument.

Also note that the variable declared outside the function are not available within the function. Either you have to declare them inside function or use global variable scope

$an = "1989";
$luna = "4";
$zi = "23";


function CalzulareZodie($date){
         global $an, $luna, zi; // If you want
         list($an,$luna,$zi)=explode("-",$date);
         if(($luna==1 && $day>20)||($month==2 && $zi<20)){
              return "Varsator";
         }else if(($luna==2 && $zi>18 )||($luna==3 && $zi<21)){
              return "Pesti";
         }else if(($luna==3 && $zi>20)||($luna==4 && $zi<21)){
              return "Berbec";
         }else if(($luna==4 && $zi>20)||($luna==5 && $zi<22)){
              return "Taur";
         }else if(($luna==5 && $zi>21)||($luna==6 && $zi<22)){
              return "Gemeni";
         }else if(($luna==6 && $zi>21)||($luna==7 && $zi<24)){
              return "Rac";
         }else if(($luna==7 && $zi>23)||($luna==8 && $zi<24)){
              return "Leu";
         }else if(($luna==8 && $zi>23)||($luna==9 && $zi<24)){
              return "Fecioara";
         }else if(($luna==9 && $zi>23)||($luna==10 && $zi<24)){
              return "Balanta";
         }else if(($luna==10 && $zi>23)||($luna==11 && $zi<23)){
              return "Scorpion";
         }else if(($luna==11 && $zi>22)||($luna==12 && $zi<23)){
              return "Sagetator";
         }else if(($luna==12 && $zi>22)||($luna==1 && $zi<21)){
              return "Capricorn";
         }
    }

and

$zodia=CalzulareZodie("Enter your date here");
echo "Zodia este: ".$zodia; 


You need to pass the variables to the function, now, judging by the start of the function it takes a string with a date separated by dashes as an arguement so you'll need to do something like:

$an = "1989";
$luna = "4";
$zi = "23";

$date = $an . '-' . $luna . '-' . $zi;  //Construct the string from the outside variables

Then you do:

$zodia=CalzulareZodie($date); //Pass constructed string to function.
echo "Zodia este: ".$zodia; 


$zodia=CalculareZodie('specify date here');


There are a couple of things wrong.

  1. You have a date argument which you are not passing in.
  2. The variables are not accessible in the function and need to be set as global like this:

    function CalzulareZodie($date){

    global $an, $luna, $zi;

    // REST OF THE FUNCTION

    }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜