-2

I have list of items for example, I want my in array to give me results both on $list1= ['apple', 'ball ']; $list2= ['apple', 'ball'];

in_array('ball',$list1) its okay for second case but not working for first case because there is space after ball if return false I mean i don't want exact match but at least want this to skip spaces which are present in the array element list!

wiki
  • 13
  • 4
  • 1
    Does this answer your question? [filter values from an array similar to SQL LIKE '%search%' using PHP](https://stackoverflow.com/questions/5808923/filter-values-from-an-array-similar-to-sql-like-search-using-php) – Simone Rossaini Aug 18 '20 at 13:48

1 Answers1

0

array_map and trim can do the job


$trimmed_array = array_map('trim', $list);
print_r($trimmed_array);
vinod
  • 236
  • 3
  • 11
  • I ma looking for its alternative `in_array('team_member',$roles) || in_array('team_member ',$roles)` – wiki Aug 18 '20 at 15:37