title: PHP- Decode JSON
body: <p>I have the following script to get search results from an API and then slice the array and dump it, I am having trouble decoding the JSON into an array, it returns <code>Array(0) {
  }</code>
  It is a wordpress shortcode</p>
  
  <p>Here is a sample of the Json that is gotten from the api:</p>
  
  <pre><code>[
    {
      "barcode": "000015426950",
      "name": "Karen's cowboy",
      "author": "Ann",
      "author_last": "Martin",
      "publisher": "New York : Scholastic, c2000.",
      "year_pub": "",
      "edition": "",
      "genre": "",
      "checkout": "out",
      "series": "",
      "callnum": "MAR",
      "fiction": "true",
      "in_house": "false",
      "timestamp": "1355835387",
      "outto": "000008388615",
      "duedate": "1372005722",
      "ISBN": "059052528X",
      "media_type": "",
      "print": "false",
      "BOXID": "2147483647",
      "uid": "10",
      "printed": ""
    },
    {
      "barcode": "000015426949",
      "name": "Karen's yo-yo",
      "author": "Ann M",
      "author_last": "Martin",
      "publisher": "New York : Scholastic, c2000.",
      "year_pub": "",
      "edition": "",
      "genre": "",
      "checkout": "out",
      "series": "",
      "callnum": "MAR",
      "fiction": "true",
      "in_house": "false",
      "timestamp": "1355835343",
      "outto": "000008388615",
      "duedate": "1373216918",
      "ISBN": "0590525115",
      "media_type": "",
      "print": "false",
      "BOXID": "",
      "uid": "10",
      "printed": ""
    },
  ...
    }
  ]
  </code></pre>
  
  <p>Here is the code used to get the JSON and paginate it,:</p>
  
  <pre><code>function book_search_form() {
  ?&gt;
  &lt;form method='get'&gt;&lt;input type='text' name='searchvalue' value='&lt;? if (isset($_GET['searchvalue'])) echo $_GET['searchvalue'];?&gt;' /&gt;&amp;nbsp;&lt;input type='submit' value='Search' /&gt;&lt;input type='hidden' name='pagenum' value='1' /&gt;&lt;/form&gt;
  &lt;br&gt;
  &lt;?php 
  if(isset($_GET['pagenum']) &amp;&amp; isset($_GET['searchvalue']))
  {
  $page=$_GET['pagenum'];
  $searchvalue = $_GET['searchvalue'];   // get the value of the page from your url
  $recordsPerPage=10; // number of records you want on your page
  $api_url = get_option('api_url');
      $api_key = get_option('api_key');
      $data = file_get_contents("$api_url/book/index.php/name/$searchvalue?key=2513619352");
      $array = (array)json_decode($data);
  
  $index=($page*$recordsPerPage)-1;
  $recordsToBeDisplayed = array_slice($array,$index,$recordsPerPage);// this array contains all the records you would want to display on a page;
  
  
  
      $total_pages=ceil(count($array)/$recordsPerPage);
      }
  else { 
  
  //use default values
  
  }
  ?&gt;
  &lt;html&gt;...&lt;body&gt;&lt;div id="records"&gt;
  &lt;?
  echo '&lt;pre&gt;';
  echo $recordsToBeDisplayed;
  echo '&lt;/pre&gt;';?&gt;&lt;!-- use the array created above to display records --&gt;
      &lt;/div&gt;
  &lt;div id="pagination"&gt;
  &lt;?
  for($j=1;$j&lt;=$total_pages;$j++){
                      if($j==$page)
                     {?&gt;
  
                     &lt;li style="display: inline;"&gt;&lt;a href="?searchvalue=&amp;pagenum=&lt;?=$j?&gt;"&gt;&lt;u&gt;&lt;?=$j?&gt;&lt;/u&gt;&lt;/a&gt;&lt;/li&gt;
                     &lt;?}else{?&gt;
                          &lt;li style="display: inline;"&gt;&lt;a href="?searchvalue=&amp;pagenum=&lt;?=$j?&gt;"&gt;&lt;?=$j?&gt;&lt;/a&gt;&lt;/li&gt;
  
  
                     &lt;?}}?&gt;
  &lt;/div&gt;
  &lt;?php
  
  
  }
  </code></pre>