Easy peasy lemon squeezy: http://www.php.net/manual/en/function.json-encode.php

<?php
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);

echo json_encode($arr);
?>

There's a post by andyrusterholz at g-m-a-i-l dot c-o-m on the aforementioned page that can also handle complex nested arrays (if that's your thing).

Answer from David Titarenco on Stack Overflow
๐ŸŒ
PHP
php.net โ€บ manual โ€บ en โ€บ function.json-encode.php
PHP: json_encode - Manual
Returns a string containing the JSON representation of the supplied value. If the parameter is an array or object, it will be serialized recursively. If a value to be serialized is an object, then by default only publicly visible properties will be included.
๐ŸŒ
ProxyScrape
proxyscrape.com โ€บ tools โ€บ php-to-json
PHP Array to JSON Converter - ProxyScrape Tools
Free online tool to convert PHP arrays to JSON format. Convert PHP array syntax to valid JSON objects and arrays with proper formatting. Perfect for PHP developers working with APIs.
Discussions

php - How to convert JSON string to array - Stack Overflow
What I want to do is the following: taking JSON as input from text area in php use this input and convert it to JSON and pass it to php curl to send request. this m getting at php from get of api ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Help converting PHP arrays to JSON format
Hi there. Iโ€™m struggling to get my head around converting arrays into JSON format. I have some code that queries my database and successfully returns 2 columns (contact_type and contact_det) into an array: array(3) ( โ€ฆ More on community.spiceworks.com
๐ŸŒ community.spiceworks.com
6
2
September 2, 2015
PHP Array to Json Object - Stack Overflow
I need to convert a PHP array to JSON but I don't get what I expect. I want it to be an object that I can navigate easily with a numeric index. Here's an example code: $json = array(); $ip = "... More on stackoverflow.com
๐ŸŒ stackoverflow.com
What is the appropriate way to encode an array into JSON?
If it's just scalar values in your array, you may as well use ext-json; that's what the JsonEncoder uses anyway IIRC. If there are objects involved, or you want to transform it in any way, you probably want to use the serializer component: https://symfony.com/doc/current/components/serializer.html More on reddit.com
๐ŸŒ r/symfony
3
1
April 24, 2023
๐ŸŒ
W3Schools
w3schools.com โ€บ php โ€บ php_json.asp
PHP and JSON
The json_decode() function is used to decode a JSON object into a PHP object or an associative array.
๐ŸŒ
Jsontophp
jsontophp.com
Convert JSON Object to PHP Array Online
JSON to PHP array converter online - Convert the given JSON object or Array into beautified PHP array that can be used instantly into your PHP file as a PHP array
Find elsewhere
๐ŸŒ
Jonathan Suh
jonsuh.com โ€บ blog โ€บ convert-loop-through-json-php-javascript-arrays-objects
Convert and Loop through JSON with PHP and JavaScript Arrays/Objects โ€” Jonathan Suh
September 30, 2014 - PHP >= 5.2.0 features a function, json_decode, that decodes a JSON string into a PHP variable. By default it returns an object. The second parameter accepts a boolean that when set as true, tells it to return the objects as associative arrays.
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ handling-json-files-with-php โ€บ lessons โ€บ parsing-json-arrays-with-php
Parsing JSON Arrays with PHP
Understanding how to parse these arrays efficiently is essential for working with complex data structures in real-world applications. In this lesson, we'll build on what you've previously learned to explore how to extract data from JSON arrays using PHP's built-in functions.
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ php โ€บ 0kvtdskv โ€บ php-array-to-json-example
How do I convert PHP Array to JSON?
Many programming languages have built-in or external libraries for creating and manipulating JSON data strings, including PHP, JavaScript, Java, C++, C#, Go, and Python. JSON file names use the .json extension. In PHP, an array is a variable that is used to store data containing various elements.
๐ŸŒ
Elastic
elastic.co โ€บ docs โ€บ reference โ€บ elasticsearch โ€บ clients โ€บ php โ€บ configuration โ€บ dealing with json arrays and objects in php
Dealing with JSON arrays and objects in PHP | PHP
By using an explicit stdClass object, we can force the json_encode parser to correctly output an empty object, instead of an empty array. This verbose solution is the only way to acomplish the goal in PHPโ€ฆ
๐ŸŒ
Scout APM
scoutapm.com โ€บ home โ€บ blog โ€บ php json_encode: serialize php objects to json
PHP Json_encode: Serialize PHP Objects to JSON | Scout Monitoring
May 1, 2020 - This will result in an Associative array being returned. ... In this post, we read about the JSON (JavaScript Object Notation) format, why it is essential, and how we can convert different PHP variables into JSON using json_encode(). We also saw how we could use ***json_decode() ***to decode JSON data into PHP variables.
๐ŸŒ
ReqBin
reqbin.com โ€บ code โ€บ php โ€บ 0uwqq41y โ€บ json-to-array-php-example
How do I convert JSON to PHP array?
To convert a JSON data string to a PHP array, you can use the json_decode($json) function.
๐ŸŒ
DevToolLab
devtoollab.com โ€บ home โ€บ tools โ€บ json to php array converter | json to php code online free
JSON to PHP Array Converter | JSON to PHP Code Online Free - DevToolLab
February 5, 2026 - Convert JSON to PHP array syntax and PHP arrays to JSON. Perfect for PHP developers working with APIs and configuration files.
๐ŸŒ
Medium
medium.com โ€บ @jochelle.mendonca โ€บ demystifying-json-and-arrays-in-php-unraveling-the-complexity-c8a1c9d51896
Demystifying JSON and Arrays in PHP: Unraveling the Complexity | Medium
March 6, 2024 - On the other hand, PHPโ€™s json_decode() function offers strong support for decoding JSON data into PHP arrays. This makes it simple for developers to scan JSON texts and transform them back into native PHP data structures for additional processing and investigation.
๐ŸŒ
Intelephense
intelephense.com โ€บ docs
Intelephense: Documentation
Intelephense will type evolve array types when mutated only if they are declared with an empty array initialiser. Otherwise they are considered to retain their initial declared, annotated or inferred type. The example below demonstrates type evolving. <?php function example(int $a): void { $a = "string"; // $a is now type string $b = []; // $b is type array and flagged as evolving $b[] = "string"; // $b is now type string[] $b[] = 9; //$b is now (string|int)[] $c = [1, 2]; // $c is type int[] and NOT flagged as evolving $c[] = "string"; // $c is still type int[] }