Check if variable exist in specific array key (PHP, MYSQLI) -


edit: solved - works expected. issue $search variable. of help.

i have typical while looks this:

while ($row = $result->fetch_assoc()) 

in $row, have user_name key looks $row["user_name"].

i have variable called $search.

theoretically, $search in key in $row array, example in $row["user_id"].

i'm trying use stripos see if there's non-case-sensitive instance $search "like", or in key, $row["user_name"].

i've tried storing $row["user_name"] in separate variable.

basically.

if(stripos($row["user_id"],$search) !== false){ echo("working"); } 

this never happens. please help!

edit: let me rephrase.

all need see if $row["user_name"] contains what's in string variable $search.

i've tried convert $row["user_name"] array, string, etc , tried in_array , stripos , nothing works.

the below work:

if (stripos("hey guys","guys")){     echo("worked");     } 

but need is

if (stripos($row["user_name"],$search)){     echo("worked");     } 

edit: var_dump looks array(2) { ["user_id"]=> string(3) "133" ["user_name"]=> string(3) "mrp" }

edit: verified both $row["user_name"] , $search strings don't issue.

<?php     $search = 'bar';     $row = array('id' => 'foo', 'name' => 'bar', 'troll' => 'zer');      // method 1: preg_match     $ret = (bool)preg_match('`(' . implode('|', array_values($row)) . ')`i', $search);      // method 2: array_search     $ret = array_search(strtolower($search), array_map('strtolower', $row)) !== false;      if ($ret) {       echo 'found';     } else {       echo 'not found';     } ?> 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -