php not recognizing array

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thecoolone

    #1

    php not recognizing array

    I am trying to loop through a mysql result array with the following
    code:

    while($count = mysql_fetch_ass oc($result))
    {
    $var1=array();
    $var1=$count["files"];
    $var2=array_sli ce($var1, 5, -1);
    print_r("$var2" );
    print "<br>";
    if(in_array("71 94", $var2))
    {print "7194 was there in the string so increment counter"; print
    "<br>";}
    }

    For some strange reason php doesnt seem to recognize the result from
    mysql_fetch_ass oc
    as an array and throws the following two error:
    Warning: in_array() [function.in-array]: Wrong datatype for second
    argument
    Warning: array_slice() [function.array-slice]: The first argument
    should be an array

    is there any syntatic mistake somewhere??
    somehow when i just do the foll it prints the array

    while($count = mysql_fetch_ass oc($result))
    {
    $var1[]=$count["files"]; // $var1[]
    $var2=array_sli ce($var1, 5, -1);
    print_r("$var2" );
    print "<br>"; }

    why is var[] strangely working and var=array() not??

  • Geoff Berrow

    #2
    Re: php not recognizing array

    Message-ID: <1168780957.484 575.79920@m58g2 000cwm.googlegr oups.comfrom
    thecoolone contained the following:
    $var1=$count["files"];
    $count["files"] is not an array it's an array element.

    Therefore $var1 is not an array either.

    --
    Geoff Berrow (put thecat out to email)
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/

    Comment

    Working...