Hi everyone! I'm the author of code.mu :)
I'd love to chat with my non-Russian audience. I'm looking for your feedback on the site and the translation quality. Let's chat:)
⊗ppSpJnOTA 17 of 83 menu
◀ ▶

Converting JSON Objects to Associative Arrays in PHP

You can make JSON objects convert into associative arrays in PHP. To do this, the second parameter of the function json_decode needs to be set to the value true.

Let's try. Suppose we have the following JSON:

<?php $json = '{ "a": 1, "b": 2, "c": 3 }'; ?>

Let's convert it into a PHP associative array:

<?php $data = json_decode($json, true); ?>

Let's check what we got:

<?php var_dump($data); // ['a' => 1, 'b' => 2, 'c' => 3] ?>

Convert the following JSON into a PHP associative array:

<?php $json = '{ "list1": ["value11", "value12", "value13"], "list2": ["value21", "value22", "value23"] }'; ?>
← →
↑
English▼
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline