Array Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Midgard
    New Member
    • Nov 2006
    • 10

    Array Problem

    $D['available_colo rs'] as 7, 6, 3, 1 coming from MySQL.

    I have this array.

    [PHP]
    echo '<pre>';
    print_r(explode (', ', $D['available_colo rs']));
    echo '</pre>';
    [/PHP]

    Output:
    Array
    (
    [0] => 7
    [1] => 6
    [2] => 3
    [3] => 1
    )

    And i have color_id at another while.

    I want this: If color_id == array() show result.

    Sorry, my english bad.

    Thanks
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    You cannot compare a variable with an array. What you can do is check if a variable is present in the array. Like this:
    [php]if (in_array($colo r_id, $array))
    show result ....
    [/php]

    Ronald :cool:

    Comment

    • Midgard
      New Member
      • Nov 2006
      • 10

      #3
      Thanks!! :)

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        You are welcome.

        Ronald :cool:

        Comment

        Working...