encoding nested json objects in php

I have a json code in JAVA, I would like to know its equivalent code in PHP.

    JSONArray objArr = new JSONArray();
    PrintWriter out = response.getWriter();
    for(int i =0 ;i<4;i++)
        JSONObject obj = new JSONObject();
        obj.put("name", "punith"+i);
        obj.put("id", "123"+i);
    JSONObject result = new JSONObject();
    JSONObject obj = new JSONObject();
    objArr = (JSONArray) result.get("result");
    obj = (JSONObject) objArr.get(0);
O/P of this code is :: 


I would like to get the same result with php code. Someone please help me.


Here you are

$resultArray = array();
    $element = array("name"=>"punith$i", "id"=>"123$i");
    array_push($resultArray, $element);
echo json_encode(array("result"=>$resultArray));

In php you have


Which stringify the object

Need Your Help

How to get the proper bounds of a view after transformation Matrix


I have a custom view where I use transformations. So far so good, function like setRotationY(), setScaleX(), setTranslationY() or even getMatrix() work as expected, I’m able manipulate my view and it

Android Debug Keytool Error

android keytool

I can't seem to get the SHA1 string from running the keytool command. When I am prompted for the password for my debug key I enter "android" and after hitting enter I get a string of weird characte...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.