SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array datatype warning

    Here's the warning:

    Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/whatsonn/public_html/includes/calendar.inc.php on line 123

    Here's the line in question:

    PHP Code:
    if(in_array(date("d/m/Y"$timestamp),$startDates)) 
    And that's all I know. Is $timestamp or $startDates the second argument, and what datatype should it be?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The first argument is the result of the function call to date, and the second is $startDates

    function(argument 1, argument 2)

    if(in_array(date("d/m/Y", $timestamp),$startDates))
    It should be an array but isn't

  3. #3
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you're using an array function. what type do you think it's argument should be? an integer?

    It seems $startDates should be defined before but failed.

  4. #4
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Dan.

  5. #5
    SitePoint Member robbin.joe's Avatar
    Join Date
    Oct 2009
    Location
    Beijing, China
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    change to
    Code:
    if(in_array(date("d/m/Y", $timestamp), array($startDates)) )

  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by robbin.joe View Post
    change to
    Code:
    if(in_array(date("d/m/Y", $timestamp), array($startDates)) )
    array() is not a typecasting function, so if $startDates is sometimes an array like it's supposed to be, this will encapsulate that array in another and the function won't work.

  7. #7
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,200
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Dan Grossman View Post
    array() is not a typecasting function, so if $startDates is sometimes an array like it's supposed to be, this will encapsulate that array in another and the function won't work.
    yes array is not a typecasting function. but we can make element an part of an array using like:
    PHP Code:
    <?php
    $startDate 
    '2010-01-14';
    echo 
    $startDate//just a string
    $new_array = array($startDate); //becomes an part of the array
    print_r($new_array);
    ?>


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
  •