title: PHP how to return a null json array if there is no data to show
body: <p>I've a situation here I've got a basket stored in session there is a delete item button on user end. I want to return a null array if there is not item in the array</p>
  
  <p>Here is my PHP code</p>
  
  <pre><code>session_start();
  
  header('Content-Type: application/json');
  require_once('includes/requireonce.php');
  
  if ( strtolower($_SERVER['REQUEST_METHOD']) == 'post' ) :
  
      if(isset($_POST['removeItem'])){
  
          $itemToRemove = htmlspecialchars($_POST['removeItem']);
  
          if(count($_SESSION['order_array']) &lt;= 1){
              unset($_SESSION['order_array']);
              print json_encode([null]);
          }else{
              unset($_SESSION['order_array'][$itemToRemove]);
              sort($_SESSION['order_array']);
              print json_encode($_SESSION['order_array']);
          }
      }
  endif;
  </code></pre>
  
  <p>jQuery function that calls that code and prints the data on screen:</p>
  
  <pre><code>$('#fixedBasket').on('click', '.removeItemCLS', function() {
      var itemIndex = $(this).attr('id'),
          cart_total = 0;
      // console.log('remove Item new: ' + itemIndex);
  
      $.post("delete_item.php",
      {
          removeItem : itemIndex
      },
      function(data){
          if(data){
              $("#cart_result").empty();
              $(data).each(function(index,item) {
                  output = setCartContent(index, item);
                  cart_total += +item.price;
                  $("#cart_result").append(output);
              });
  
              $("#cart_total").empty();
              $("#cart_total").html(cart_total.toFixed(2));
          }else{
              $("#cart_result").empty();
              $("#cart_total").empty();
          }
      });
  
      return false;
  });
  </code></pre>
  
  <p>setCartContent below</p>
  
  <pre><code>function setCartContent(index, data){
      return '&lt;div class="row"&gt;' + 
          '&lt;div class="col-md-2"&gt;&lt;a href="#" id="' + index + '" class="removeItemCLS"&gt; &lt;span class="glyphicon glyphicon-minus-sign" aria-hidden="true"&gt;&lt;/span&gt; &lt;/a&gt;&lt;/div&gt;' +
          '&lt;div class="col-md-7"&gt;' + data.product_name + '&lt;/div&gt;' + 
          '&lt;div class="col-md-3"&gt;&lt;div class="pull-right"&gt;' +  data.price + '&lt;/div&gt;&lt;/div&gt;' + 
      '&lt;/div&gt;&lt;br /&gt;';
  }
  </code></pre>
  
  <p>I want to return a null and catch a null on jQuery side so if it is null just empty the div's </p>
  
  <p>Any ideas?</p>
  
  <p>Regards</p>