0
$array = array('hey','hi','hello');

if (in_array('hei',$array)) echo 'aaa';

This will not work, because there is no "hei" in the array, but I need something to search not with exact string.

In mySQL we have WHERE x ALIKE y. What can we use to find for alike string in array, not exact?

Thanks

2

1 Answer 1

2

Use this function:

    function like_in_array( $sNeedle , $aHaystack )
    {

        foreach ($aHaystack as $sKey)
        {
            if( stripos( strtolower($sKey) , strtolower($sNeedle) ) !== false )
            {
                return true;
            }
        }

        return false;
    }

   if(like_in_array('hei', $array)) {
      echo 'in array';
   }
Sign up to request clarification or add additional context in comments.

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.