Im working and new how to generate json on arrays in php. is there any alternate ways or best way to generate json on php?
HERE'S MY CODE:
<?php
$array =
array(
'name' =>
array(
'gender'=> 'male-female',
'location' => 'adress here'),
'age' => 'age here',
'about me' => array(array(
'birthday' => 'MM-DD-YYYY',
'status' => 'status here',
'childrens' => 'childrens here')),
'employer' => array('bank','fastfood','sales'),
'nameofchildrens' => array(array(
'name1' => "namehere1" , 'employer2' => array('bank','fastfood','sales'),
'name2' => "namehere2" , 'employer1' => array('bank','fastfood','sales'))),
'relatives' => array(),
'siblings' => array(),
'ancestors' => array(),
'pets' => array(array('dog','cat','rabbit')),
'sports' => array('basketball','badminton','volleyball'),
);
echo json_encode($array);
?>
This how I generate a json with format I wanted. It's working but is there anyone can provide me a alternate ways to generate a json format like this?
OUTPUT:
{"name":{"gender":"male-female","location":"adress here"},"age":"age here","about me":[{"birthday":"MM-DD-YYYY","status":"status here","childrens":"childrens here"}],"employer":["bank","fastfood","sales"],"nameofchildrens":[{"name1":"namehere1","employer2":["bank","fastfood","sales"],"name2":"namehere2","employer1":["bank","fastfood","sales"]}],"relatives":[],"siblings":[],"ancestors":[],"pets":[["dog","cat","rabbit"]],"sports":["basketball","badminton","volleyball"]}