title: identify json object consisting of different number of items
body: <p>Here is my <code>json</code> object</p>
  
  <pre><code>[  
  {  
      "grup":"",
      "barkod":"1234",
      "amount":"1",
      "selling price":"215",
      "cost":"68.69"
  },
  {  
      "grup":"4444",
      "barkod":"",
      "ammount":"1",
      "selling price":"49.9",
      "cost":"75"
  },
  {  
      "grup":"3333",
      "barkod":"091986 ",
      "amount":"1",
      "selling price":"69.9",
      "cost":"16.56"
  },
  {  
      "cost":"300",
      "pay type":"cash",
      "taksit":"1"
  },
  {  
      "cost":"200",
      "pay type":"BANK",
      "taksit":"7"
  },
  {  
      "idNo":""
  }
  ]
  </code></pre>
  
  <p>this object is sent via ajax  php  server. Then, turns it into a php array: </p>
  
  <pre><code> $datax = json_decode(file_get_contents("php://input"));
  </code></pre>
  
  <p>I want  for first 3  elements (number can change)   run insert statment for <code>table1</code>,
  for 4. and 5. elements  run insert statment for <code>table2</code>  and so on</p>