MantiNL
MantiNL

Reputation: 69

stripos(); searching in 2 variables

Here is my function:

function search_title_and_vendor{
    if (stripos($title, 'Tsugi') !== false) {
        if (stripos($vendor, 'Puma') !== false) {
            return 'Puma Tsugi';
        } else {
            return '';
        }
    }   
}

Where the variables are:

$title = 'Puma Tsugi'
$vendor = 'Puma'

As you can see I tried to nest the if statement to search for two variables, if they match, return 'Puma Tsugi'. However, this returns nothing.

In my file, I also have occurrences with, for example, Vans Tsugi, where $vendor = 'Vans'; and $title = 'Vans Tsugi sneakers'.

How can I search for a combination like this and, return a given value?

Upvotes: 0

Views: 111

Answers (1)

Zak
Zak

Reputation: 7523

You should pass your info into the function using parameters -- like so:

$search_result = search_title_and_vendor('Puma Tsugi','Puma');

Then your original function should contain the variable declarations in the parentheses:

function search_title_and_vendor($title, $vendor){

So the full function should look like:

function search_title_and_vendor($title, $vendor){
if (stripos($title, 'Tsugi') !== false) {
    if (stripos($vendor, 'Puma') !== false) {
        return 'Puma Tsugi';
    }
    else {return '';}
}   
}

Then $search_result should contain the desired result:

echo $search_result;

Upvotes: 0

Related Questions