0

I would like to check the following condition with php

$string = '10-15~15-20~20-25~';

    $stringArray = explode('~',rtrim($string,'~'));

    if (in_array('20-25', $stringArray)) {
       echo 'Found';
    }
    else
    {
        echo 'Not found';
    }

20-25 is present in my array but, it always shows not found

2 Answers 2

1

There are some errors in your code. Here is a corrected version.

$string = '10-15~15-20~20-25~';
$stringArray = explode('~',rtrim($string,'~')); // corrected here, missing "$" before "string"
if (in_array('20-25', $stringArray)) { // corrected here, wrong variable name "priceArray"
   echo 'Found';
}
else
{
    echo 'Not found';
}
Sign up to request clarification or add additional context in comments.

Comments

0

replace $priceArray with $stringArray. It's just a typo. You are searching "20-25" in non-initialized variable.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.