SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict marylin77's Avatar
    Join Date
    Aug 2003
    Location
    Spain
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    array as argument in a function

    I have this array:
    PHP Code:
    $arraydias=array(1,2,3,4,7,9); 
    What I have to write in the function definition to pass $arraysdias to the function?
    Definition function (bad definition:[ )
    PHP Code:
    function fechaexamenes($dias[]="",$mes,$aņo=""
    $mes and $aņo are "normal" variables but I want $dias to be an array and besides it can be not definied (to do that i write="")
    any solution?
    Regards from Spain.

  2. #2
    SitePoint Zealot cmorbutts's Avatar
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    You're almost there... try this instead...

    PHP Code:
    [font=Courier][color=#006600]$aryDias = array("1", "2", "3");[/color][/font]
    [font=Courier][color=#006600]$mes = "hello";[/color][/font]
    [font=Courier][color=#006600]$aņo = "byebye";[/color][/font]
     
    [font=Courier][color=#006600]function fechaexamenes($aryDias, $mes, $aņo) {}[/color][/font] 

  3. #3
    SitePoint Zealot cmorbutts's Avatar
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One more time...
    PHP Code:
    $aryDias = array("1""2""3");
    $mes "hello";
    $ano "byebye";
     
    function 
    fechaexamenes($aryDias$mes$ano) {} 

  4. #4
    SitePoint Addict marylin77's Avatar
    Join Date
    Aug 2003
    Location
    Spain
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ohh...a fatal error is showed me :[
    Fatal error: Maximum execution time of 30 seconds exceeded in c:\archivos de programa\easyphp\www\miphp\calenarray.php on line 30
    My whole code is here:
    PHP Code:
    <?
    $fecha=getdate();
    function fechaexamenes($dias,$mes,$aņo=""){
    global $fecha;

    echo "<br>";

    $tablemes= "
    <table>
    <tr>";
    for ($i=1;$i<=diaultimo($mes);$i++){
    $diasmes=date(d,mktime(0,0,0,$mes,$i,$fecha[year]));
    for($j=0;j<count($dias);$j++){
    if ($diasmes==$dias[j]){
    $color=red;
    $ruta="detalles.php";
    $liga="<a href=\"$ruta\">";
    $finliga="</a>";
    $tablemes .="<td>$liga<font color=$color>
    $diasmes &nbsp;</font>$finliga
    </td>";

    }//cierro if
    else{
    $color=black;
    unset($liga);
    $tablemes .="<td>$liga<font color=$color>
    $diasmes &nbsp;</font>$finliga
    </td>";

    }//cierro else
    }//cierro for
    if(($diasmes==7)||($diasmes==14)||($diasmes==21)||($diasmes==28)){
    $tablemes .="</tr>
    <tr>";

    }
    }//cierro el for
    $tablemes .="</tr></table>";
    return "$tablemes";

    }//cierro function

    function diaultimo($mes){
    global $fecha;
    if ($mes<12){
    return date("d",mktime(0,0,0,($mes+1),0,$fecha[year]));
    }
    else if ($mes==12){

    return date("d",mktime(0,0,0,1,0,$fecha[year]));
    }

    }//cierro function diaultimo
    $arraydias=array(1,2,3);
    $tabla= fechaexamenes($arraydias,08,"");//genero mes de Agosto del aņo actual si no especifico
    echo "<hr>";
    echo "$tabla";
    echo "<hr>";

    ?>
    Last edited by marylin77; Oct 16, 2003 at 17:00.

  5. #5
    SitePoint Zealot cmorbutts's Avatar
    Join Date
    Apr 2002
    Location
    Sydney, Australia
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your second for loop is casing the problem.

    for($j=0;j<count($dias);$j++){

    change to

    for($j=0;$j<count($dias);$j++){

  6. #6
    SitePoint Addict marylin77's Avatar
    Join Date
    Aug 2003
    Location
    Spain
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have solved my code:
    there was a logic problem.
    The right code is here:
    PHP Code:

    <?
    $fecha=getdate();
    function fechaexamenes($dias,$mes,$aņo){
    global $fecha;


    echo "<br>";

    $tablemes= "
    <table>
    <tr>";
    /////
    $i=1;
    if ($aņo==""){
    $aņo=$fecha[year];
    }

    while($i<=diaultimo($mes,$aņo)){
    $diasmes=date(d,mktime(0,0,0,$mes,$i,$aņo));
    if (in_array($diasmes,$dias)){
    $color=red;
                $ruta="detalles.php";
                $liga="<a href=\"$ruta\">";
                $finliga="</a>";
                }
                else{
                $color=black;
                unset($liga);

                }
    $tablemes .="<td>$liga<font color=$color>
                $diasmes &nbsp;</font>$finliga
                </td>";


        if(($diasmes==7)||($diasmes==14)||($diasmes==21)||($diasmes==28)){
            $tablemes .="</tr>
            <tr>";

                }
    $i++;
    }//cierro while
    /////


    $tablemes .="</tr></table>";
    return "$tablemes";

    }//cierro function

    function diaultimo($mes,$aņo){
    global $fecha;
    if ($mes<12){
    return date("d",mktime(0,0,0,($mes+1),0,$aņo));
    }
    else if ($mes==12){

    return date("d",mktime(0,0,0,1,0,$aņo));
    }

    }//cierro function diaultimo
    $arraydias=array(1,2,3);
    $tabla= fechaexamenes($arraydias,02,"2000");//genero mes de febrero del aņo 2000 o el que quiera si no especifico
    echo "<hr>";
    echo "$tabla";
    echo "<hr>";


    ?>
    Last edited by marylin77; Oct 16, 2003 at 17:36.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •