title: Sending JavaScript String Array to PHP Web service
body: <p>I am trying to send a JavaScript String Array (<code>arrayItems</code>) to a PHP Web service in order to send a query to a MySQL database. Nonetheless, no data is returned from the Web service. Data is only correctly returned from the Web service when the JavaScript String Array has only 1 item. </p>
  
  <p><em>The Web service is in PHP 5.6.30.</em></p>
  
  <p>Sample of HTML to display the data returned:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li ng-repeat="item in arrayInfo track by $index"&gt;ID: {{ item.idFruit }}, 
  name: {{ item.name_fruit }}&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Sample of the <code>Ctrl</code> controller:</p>
  
  <pre><code>angular.module('myApp').controller('Ctrl', ['$scope', 'services', Ctrl]);
  
  function Ctrl($scope, services) {
      var arrayItems = ["apple", "banana", "orange"];
      services.getInfo(arrayItems).then(function(data){
         $scope.arrayInfo = data.data;
      });
  };
  </code></pre>
  
  <p>Sample of the app.js to send request to the Web service:</p>
  
  <pre><code>.factory('services', ['$http', function($http){
      var serviceBase = 'services/';
      var obj = {};
      obj.getInfo = function (arrayItems) {
          return $http.get(serviceBase + 'get_info?arrayItems=' + arrayItems);
      };
      // return obj
      return obj;
  }]);
  </code></pre>
  
  <p>Sample of the Web service in PHP:</p>
  
  <pre><code>private function get_info(){
      if($this-&gt;get_request_method() != "GET"){
          $this-&gt;response('', 406);
      }
      $arrayItems = (array)$this-&gt;_request['arrayItems'];
      $fruits = implode("','", $arrayItems);
      $query = "SELECT idFruit, name_fruit FROM Table_Fruits WHERE name_fruit IN 
  ('$fruits')";
      $r = $this-&gt;mysqli-&gt;query($query) or die($this-&gt;mysqli-&gt;error.__LINE__);
      if($r-&gt;num_rows &gt; 0){
          $result = array();
          while($row = $r-&gt;fetch_assoc()){
              $result[] = $row;
          }
          $this-&gt;response($this-&gt;json($result), 200); // send user details
      }
      $this-&gt;response('', 204);   // send user detail
  }
  </code></pre>
  
  <p>Thank you *</p>