Skip to content

Instantly share code, notes, and snippets.

@javedbaloch4
Created March 6, 2018 17:40
Show Gist options
  • Save javedbaloch4/73bbed308b79f5e72b4c74250e9b1023 to your computer and use it in GitHub Desktop.
Save javedbaloch4/73bbed308b79f5e72b4c74250e9b1023 to your computer and use it in GitHub Desktop.
PHP - Convert Array into Object
<?php
// Array
$brands = ['electronics' => ['Dell','Hp','Compaq','Acer']];
// Encode Array into JSON
$json = json_encode($brands);
// Decode the json data, Object is ready
$object = json_decode($json);
// Check the result
echo "<pre>", print_r($object), "</pre>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment