How to convert a PHP array into JSON
Do you know How to convert a PHP array into JSON, I will explain step by step in this tutorial.
If you are working with small frontend applications and you may not use a high-level framework like Laravel. so that time you can use the help of this.
So I will explain How to Convert PHP array to JSON.
At the top of your PHP script, you have to add a header that mentions this is JSON.
header('Content-Type: application/json');
How lets create an array
$array = array(); $array['status'] = "true"; $array['name'] = "John"; $array['email'] = "[email protected]";
Convert this array to a JSON
echo json_encode($array,JSON_PRETTY_PRINT);
Now lets Look into the Example Source Code
Convert a PHP array into JSON Example
<?php header('Content-Type: application/json'); $array = array(); $array['status'] = "true"; $array['name'] = "John"; $array['email'] = "[email protected]"; echo json_encode($array,JSON_PRETTY_PRINT); ?>
That’s all. Hope you like this
Check out more awesome PHP Tutorials
Post Your Questions on our forum
Post a question on ForumShare with your friends:
How to integrate Paypal API in Laravel
Are you looking to integrate Paypal API in your Laravel project for seamless payment processing? Look no further! In this […]
April 3, 2024
How to integrate Razorpay API in Laravel
Integrating payment gateways into web applications has become an essential part of e-commerce websites. In this tutorial, we will discuss […]
April 3, 2024
Laravel 11 Ajax CRUD Operation Tutorial Example
**Mastering CRUD Operations with Laravel 11 Ajax: A Comprehensive Tutorial** In the world of web development, interaction between the front-end […]
April 3, 2024
Login as Client in Laravel – Login with user id
**Unlock the Power of Laravel with Login as Client – Login with User ID** Laravel, the popular PHP framework, offers […]
April 3, 2024
Digital Marketing Toolkit
Get Free Access to Digital Marketing Toolkit. You can use all our tools without any limits
Get Free Access Now