I have some functions that returns nothing or some value (obvious), and also having a little trouble with the if and closing, is there a good way to do this? I want to return the value after checking if any of the strings are not empty.
Actually it is a search results page. I can have result by links that follow this structure:

search_url(array("xxx" => "name");

and in the array for xxx's is either:

"sPattern"=> "name"
"sRegion"=> "name"
"sCity"=> "name"

so how to do this?

<?php if( sPattern > '') { ?> 
echo  result
else
<?php if( sRegion > '') { ?> 
echo result
else
<?php if( sCity > '') { ?> 
echo result
if nothing match do this
Member Avatar for diafol

I'm not sure what you're trying to do, but maybe:

if(in_array($name, $array)){
    echo "found";
}else{
    echo "not found";
}

Maybe this could help or else could you please elaborate your requirement

search_url(array("xxx" => "name"));

function search_url($air){
    if ( empty($air) ) {
        echo "Empty";
    } else if( $air['sPattern'] ) { 
        echo  $result1;
    } else if( $air['sRegion'] ) { 
        echo $result2;
    } else if( $air['sNname'] ) { 
        echo $result3;
    }
}

ok, first there is a search form that takes the sPattern:

<input type="text" name="sPattern"  id="query" class="input-text" value="" etc.

then, there are search links, example:

search_url(array("sRegion" => "florida"));

where the xxx I talked about can be sRegion, sCity or sCategory
"name" can be anything e.g. a name of the category, city, region, whatever I put in there.

All links and search activity goes to results-page.
Then, if results are not found I need to echo this like "there are no results found for "name".
In order to do this I need to check if sPattern, sRegion or sCity was used.
Of course, the value for sPattern can be retrieved from it's function through the search form.
If that is emtpy I need to check which of the others was used from the the links.

Member Avatar for diafol

You can do an array_search()

This will return the array key(s) of any matches.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.