Gagan
Gagan

Reputation: 294

How to find if a string contains a specific integer php

I have a variable that outputs as 0 type int I have another string that outputs as 0,1,2.

I am trying to find out if the string contains that very integer, both of these are dynamic values and being fetched from database.

I have tried -

if (strpos($string, $int) !== false) {
            echo 'true';
        }

But it is not working.

Upvotes: 0

Views: 58

Answers (1)

RainDev
RainDev

Reputation: 1128

You can use type conversion:

if (strpos($string, (string) $int) !== false)
            echo 'true';

Upvotes: 1

Related Questions