title: split string into an array and use each item of the array in a query string
body: <p>I've searched through all the topics dealing with splitting strings into an array. But I have not actually come across what concerns my needs.</p>
  
  <p>On the searchbox, a user types any string of any length (I cannot tell the length of words). On submit, the php script collects the value as $q.</p>
  
  <p>Example:</p>
  
  <ol>
  <li>Let's say <code>$q="users typed in search query of any length."</code></li>
  <li>php to split each word in <code>$q</code> into a <code>$stringArray</code> as in <code>("users","type","in","search","etc")</code>.</li>
  <li>php to iterate each item of the <code>$stringArray</code> as in: <code>for(each $stringArray as $i);</code></li>
  <li>Run a query using each <code>$i</code> of the array to find matches and display all rows that match any of <code>$q</code>.</li>
  </ol>
  
  <p>PHP CODE</p>
  
  <pre><code>&lt;?php
  require_once('../data/conString_mysqli.php');
  
  if(isset($_POST['services'])){$q = trim($_POST['services']);}else if(isset($_REQUEST['q'])){$q = trim($_REQUEST['q']);}
  else if(isset($_REQUEST['s'])){$s = trim($_REQUEST['q']);}else{header('Location:../home/');}
  
  ?&gt;
  
  &lt;?php
  
  $stringArray = explode(" ", $q);//split using spaces
  
  foreach (array($stringArray) as &amp;$q) {  
  ?&gt;
  
  &lt;?php
  //run a search query here
  $search_query = mysqli_query($connect,"SELECT * FROM service_providers WHERE INSTR(pname, '".$q."') OR INSTR(bizaddr, '".$q."') OR INSTR(bizname, '".$q."') OR INSTR(bizdesc, '".$q."') OR INSTR(pmobile, '".$q."') OR INSTR(pemail, '".$q."') OR INSTR(bizcat, '".$q."') OR INSTR(pmobile, '".$q."')ORDER BY bizname");
  
      $records = mysqli_num_rows($search_query);
      if(!$records &gt;= 1){
          die(mysql_error());//('&lt;script type="text/javascript"&gt;alert("PROVIDERS SEARCH RESULT \n\nCould not find a match. \nTry using one word, exact words. \nYou can search by category. Just type the category name (tv repairs, air conditioning, painting, car repairs, carpentry, plumbing, tiles, rug, washing, catering, cakes, creams, computer, software, hardware etc. \n\nDo not use periods, commas, and other symbols!");window.location="test_array.php?q='.$q.'";&lt;script&gt;');
      }else {
          while($row = mysqli_fetch_array($search_query)){
              $pcode = $row['pcode'];
              $bizname = $row['bizname'];
              $bizaddr = $row['bizaddr'];
              $bizdesc = $row['bizdesc'];
              $pname = $row['pname'];
              $pmobile = $row['pmobile'];
              $pemail = $row['pemail'];
              if($row['bizcat'] ==''){
                  $category = "UNKNOWN CATEGORY";}
              else{$category = $row['bizcat'];}
  ?&gt;
  &lt;?php
              echo $pcode .'&lt;br /&gt;';
              echo $bizname .'&lt;br /&gt;';
              echo $bizaddr .'&lt;br /&gt;';
              echo $bizdesc .'&lt;br /&gt;';
              echo $category .'&lt;br /&gt;';
              echo $pname .'&lt;br /&gt;';
              echo $pmobile .'&lt;br /&gt;';
              echo $pemail .'&lt;br /&gt;';
              echo '--------------------' .'&lt;br /&gt;';
              }
          }
  ?&gt;
  
  &lt;?php
  }
  ?&gt;
  </code></pre>
  
  <p>When I run this code, it returns an error below:</p>
  
  <pre><code>Notice: Array to string conversion in C:\Wamp\www\servicehub.ng\find\test_array.php on line 17
  </code></pre>