Below are the examples to convert an array into JSON.
Example-1:
<?php
//create an array that contains another
// array with key value pair
$arr=array(array
("name"=>"sirisha","age"=>"23"),array("name"=>"swapna","age"=>"25"),array("name"=>"veena","age"=>"17"));
//evary array will be coonverted to an object
echo json_encode($arr);
?>
<?php
//declare two demenssional associative array
//array and initilize it
$arr=array("first"=>array("id"=>1,"product_name"=>" dell laptop","cost"=>21000),"second"=>array("id"=>2,"product_name"=>"lenovo laptop","cost"=>50000),"third"=>array("id"=>3,"product_name"=>"HP laptop","cost"=>45000));
//every array will be convreted to an object
echo json_encode($arr);
?>