multi array search value no need exact match - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.

Name: multi array search value no need exact match fullscreencopydownloadembedprint


Your result can be seen below.

Result of php executing





Full code of multi array search value no need exact match.php

  1. <?php
  2. $result = 
  3.         array(
  4.         array(
  5.         0 => 'blue', 
  6.         1 => 'red', 
  7.         2 => 'green string', 
  8.         3 => 'red ', 
  9.         4 => 'Black'
  10. ),
  11.         array(
  12.         0 => 'blue one', 
  13.         1 => 'red one', 
  14.         2 => 'green string one', 
  15.         3 => 'Car one', 
  16.         4 => 'Black Car one'
  17. ),
  18.         array(
  19.         0 => 'blue two', 
  20.         1 => 'red two', 
  21.         2 => 'green string two', 
  22.         3 => 'two Car ', 
  23.         4 => 'Black Car two'
  24. )
  25. );
  26.  
  27. $filterBy='Car';
  28.  
  29. foreach ($result as $key => $valuea) {
  30. foreach ($valuea as $value) {
  31.  
  32.   if (strpos($value, $filterBy) !== false) { 
  33.         $new[] = $value; 
  34.   }
  35.        
  36. }
  37. }
  38. echo '<pre>'; print_r(array($new)); echo '</pre>'; 
  39.  
File Description
  • multi array search value no need exact match
  • PHP Code
  • 25 Aug-2022
  • 566 Bytes
You can Share it: