Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts

    array_search() for values over a certain number?

    Hi!

    I'm trying to search for any number greater than or equal to 1.
    I know this must be really simple, but I can't seem to find how to do this?

    PHP Code:
    <?php
    array_search
    (1$array);
    ?>
    I also thought of:

    PHP Code:
    <?php
    $limit 
    >= 1;
    array_search($limit$array);
    ?>
    I'm not even sure if that's legal syntax lol...
    Last edited by RonnyNishimoto; 08-09-2012 at 01:24 AM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Use a filter.
    PHP Code:
    define('GREATER_THAN'0);
    function 
    greaterThanOne($v)
    {
        return 
    is_numeric($v) ? $v >= GREATER_THAN false;
    }

    $a range(-1010);
    print_r(array_filter($a'greaterThanOne')); 
    You need to use a defined constant or a global (not recommended).

  • Users who have thanked Fou-Lu for this post:

    RonnyNishimoto (08-08-2012)

  • #3
    New Coder
    Join Date
    Jul 2012
    Posts
    85
    Thanks
    53
    Thanked 0 Times in 0 Posts
    Thanks Fou! I will check it out!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •