Problem with arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • iblamemicrosoft@gmail.com

    Problem with arrays

    What I'm trying to do is check if the dates in the array $holi[]
    matches $evalday (not in an array)
    but with limited success the data in the array is:

    $holi[1] = 2006-06-20;
    $holi[2] = 2006-06-28;
    $holi[3] = 2006-07-19;
    $holi[4] = 2008-06-24;
    $holi[5] = 2006-06-30;

    $evalday = date("Y-m-d", strtotime("+ 1 days");

    if($evalday == $holi) {
    echo("For the purpose of this excercise, $evalday is a holiday");
    }

    Thanks in advance.

  • lorento

    #2
    Re: Problem with arrays

    Try array_search() function:

    if (array_search($ evalday, $holly))
    echo("For the purpose of this excercise, $evalday is a holiday");


    --



    iblamemicrosoft @gmail.com wrote:[color=blue]
    > What I'm trying to do is check if the dates in the array $holi[]
    > matches $evalday (not in an array)
    > but with limited success the data in the array is:
    >
    > $holi[1] = 2006-06-20;
    > $holi[2] = 2006-06-28;
    > $holi[3] = 2006-07-19;
    > $holi[4] = 2008-06-24;
    > $holi[5] = 2006-06-30;
    >
    > $evalday = date("Y-m-d", strtotime("+ 1 days");
    >
    > if($evalday == $holi) {
    > echo("For the purpose of this excercise, $evalday is a holiday");
    > }
    >
    > Thanks in advance.[/color]

    Comment

    • iblamemicrosoft@gmail.com

      #3
      Re: Problem with arrays

      Thank you, in_array($evald ay, $holi) worked. I should have done this
      database instead for my school project.

      Comment

      • Bob Stearns

        #4
        Re: Problem with arrays

        iblamemicrosoft @gmail.com wrote:
        [color=blue]
        > What I'm trying to do is check if the dates in the array $holi[]
        > matches $evalday (not in an array)
        > but with limited success the data in the array is:
        >
        > $holi[1] = 2006-06-20;
        > $holi[2] = 2006-06-28;
        > $holi[3] = 2006-07-19;
        > $holi[4] = 2008-06-24;
        > $holi[5] = 2006-06-30;
        >
        > $evalday = date("Y-m-d", strtotime("+ 1 days");
        >
        > if($evalday == $holi) {
        > echo("For the purpose of this excercise, $evalday is a holiday");
        > }
        >
        > Thanks in advance.
        >[/color]
        You either have to test each element separately [foreach()
        if($holiday = $evalday)...] or use the builtin function
        inarray($evalda y, $holi).

        Comment

        Working...