How to convert php array to json object with example?
In this example, we will lean to how to convert json objects of array into the php array. we will convert php array into json string. we can convert json object to associative array in php using json_encode. we can also force convert json object by "JSON_FORCE_OBJECT" parameter.
We many times require to convert php array to json array in php application like if you are creating any web services. you always need to send data as json response. Also when you are working with ajax request at that time also you need to send json response because it will easily to getting data and display them.
In this tutorial, you can see bellow example with simple way to converting json object of php array example. also with force convert json object and php convert json object to associative array. So let's there are three example so you can use anything that you require.
$languagesJSON = json_encode($languages);
$languagesJSONObject = json_encode($languages, JSON_FORCE_OBJECT);
$details = ['name'=>'Hardik', 'website'=>'itsolutionstuff.com'];
$jsonDetails = json_encode($details);
I hope it can help you...
- Laravel 5 manual pagination with array example
- How to remove specific value from php array?
- How to remove undefined value from jquery array?
- How to get maximum key value of array in PHP?
- How to remove empty values from array in PHP?
- How to add prefix in each key of PHP Array?
- How to get minimum key value of array in PHP?
- How to remove null values from array in PHP?