Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Enhancing a Simple PHP Application Adding Search: Model Performing the Search

Leigh Maher
Leigh Maher
21,830 Points

Ok to use is_int function here?

When I was trying to work out the logic of using the !==false here, I thought it might be easier to check if the result is an integer instead of not false. For me if I was to look back at this at a later stage it might make it more readable.

It gave me the same result in this instance, so I'm wondering is it ok to use that function instead?

Here's the code I used:

<?php
function get_products_search($s) {
    $results = array();
    $all = get_products_all();
    foreach ($all as $product) {
        $name = $product['name'];
        $pos = stripos($name, $s);
        if (is_int($pos)) {
            $results[] = $product;  
        }
    }
    return $results;
}
?>