Advertisement
cdsatrian

Latihan json

Jan 23rd, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. <?php
  2. $data=array(
  3.   "61" => array("sku"=>"a","unit_price"=>"1.0000","supplier_id"=>"61","sku_id"=>"7"),
  4.   "62" => array("sku"=>"b","unit_price"=>"2.0000","supplier_id"=>"62","sku_id"=>"3"),
  5.   "63" => array("sku"=>"c","unit_price"=>"3.0000","supplier_id"=>"63","sku_id"=>"4"),
  6.   "64" => array("sku"=>"d","unit_price"=>"4.0000","supplier_id"=>"64","sku_id"=>"10"),
  7.   "65" => array("sku"=>"e","unit_price"=>"5.0000","supplier_id"=>"65","sku_id"=>"9"),
  8.   "66" => array("sku"=>"f","unit_price"=>"6.0000","supplier_id"=>"66","sku_id"=>"2"),
  9.   "59" => array("sku"=>"g","unit_price"=>"7.0000","supplier_id"=>"59","sku_id"=>"11"),
  10.   "67" => array("sku"=>"h","unit_price"=>"8.0000","supplier_id"=>"67","sku_id"=>"5"),
  11.   "68" => array("sku"=>"i","unit_price"=>"9.0000","supplier_id"=>"68","sku_id"=>"8"),
  12.   "69" => array("sku"=>"j","unit_price"=>"10.0000","supplier_id"=>"69","sku_id"=>"6"),
  13.   "70" => array("sku"=>"k","unit_price"=>"11.0000","supplier_id"=>"70","sku_id"=> "1")
  14. );
  15. $json=json_encode($data);
  16. ?>
  17. <!DOCTYPE html>
  18. <head>
  19.   <title>Latihan JSON</title>
  20.   <head>
  21.   <body>
  22.     <script>
  23.     var sumber=<?php echo $json;?>;
  24.     function getData(index)
  25.     {
  26.       return sumber[index];
  27.     }
  28.     var data=getData("66");
  29.     alert(data['sku']+"--"+data['unit_price']+"--"+data['supplier_id']+"--"+data['sku_id']);
  30.     </script>
  31.   </body>
  32. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement