SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    variable >=0 or null?

    I have the following below.........how do I also check if $catkey is null?

    if ($catkey >=0)

    Thanks!

  2. #2
    SitePoint Evangelist ClickHeRe's Avatar
    Join Date
    Mar 2005
    Location
    Ottawa, Canada
    Posts
    580
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if ( $catkey != NULL && $catkey >= 0 ) {

    }
    David

  3. #3
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    Or...

    PHP Code:
    if ( !is_null($catkey) && $catkey >= ) {


    Does exactly the same as ClickHere's code

  4. #4
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok.....here is some code I have.
    Now I am getting an error on the array_key_exists function saying...
    Warning: array_key_exists() [function.array-key-exists]: The first argument should be either a string or an integer


    PHP Code:
    $catkey array_search($key$cat);
    if ( !
    is_null($catkey) && $catkey >= )
    {
        if (
    array_key_exists($catkey$name)){ 
    Any ideas? It is a number.............

  5. #5
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Are all the keys in $cat numbers? It's not an associative array (such as what you'd get from mysql_fetch_result)?

  6. #6
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry........no it is an array built from an XML file.

    Looks like they are strings......

    problem i have is........why does '0' (zero) not fall into this loop?
    PHP Code:
                if ( !is_null($catkey) && $catkey <>'')
                { 

  7. #7
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    $catkey is being assigned the result of array_search(), which if your array is indexed by strings, will be a string, not a number.

  8. #8
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes correct....got that.

    Last question........if my array_search comes back with '0' (zero as a string) then why won't....if ($catkey <>'') work?

  9. #9
    SitePoint Enthusiast
    Join Date
    Sep 2005
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry nevermind.....i did a trim and all is good now. Thanks for all the responses.

    if (trim($catkey) <>'')


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
  •