0

I'm trying to update the "$searchValue" below to include a wildcard before & after so if the string in "$searchValue" is found anywhere in the $label it will work. Any ideas on how to do that?

        foreach($json as $key=>$value){

            foreach($value as $item)
            {
                if($item->$label == "$searchValue")
                {
                    echo $item->title.'<br>';
                }
            }    
        }

Thanks for your help!

Mr. B
  • 2,531
  • 6
  • 26
  • 39
  • What you're actually trying to do is determine whether the search value appears as a substring of the values you're checking against, which you can do with [`strpos`](http://php.net/strpos). – Marty Mar 10 '19 at 02:31

1 Answers1

1
foreach($json as $key=>$value){

        foreach($value as $item)
        {
            if(strpos($item->$label, $searchValue) !== false) 
            {
                echo $item->title.'<br>';
            }
        }    
    }
Taher
  • 11,602
  • 2
  • 29
  • 44