Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6773911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:43:27+00:00 2026-05-26T15:43:27+00:00

this is the json that my code produces { aaa:1, b:2, c:3, d:4, e:5,

  • 0

this is the json that my code produces

{
"aaa":1,
"b":2,
"c":3,
"d":4,
"e":5,
"fff":{"a":11111,"b":222222,"c":33333,"d":444454,"e":55555555}
}

and this is the code

<?php
$c = array('a' => 11111, 'b' => 222222, 'c' => 33333, 'd' => 444454, 'e' => 55555555 );
$arr = array('aaa' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5 , 'fff'=>$c);
echo json_encode($arr);
?>

but I want to have some structure like this

{
"aaa":1,
"b":2,
"c":3,
"d":4,
"e":5,
"fff":{"a":11111,"b":222222,"c":33333,"d":444454,"e":55555555},
"last":[
      {
        "id": 8817,
        "loc": "NEW YORK CITY"
      },
      {
        "id": 2873,
        "loc": "UNITED STATES"
      },
      {
        "id": 1501,
        "loc": "NEW YORK STATE"
      }
    ]
}

I am new in json and php and I need this fast so I do not have time to read about this json structure… So please if someone know how to add this last element please provide some php code.

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:43:27+00:00Added an answer on May 26, 2026 at 3:43 pm
    • Take the “json-encoded” string and pass it to json_decode()
    • assign the return value to a variable
    • pass that variable to var_export() to get a “php-encoded” string representation of the data.

    e.g.

    <?php
    $json = '{
    "aaa":1,
    "b":2,
    "c":3,
    "d":4,
    "e":5,
    "fff":{"a":11111,"b":222222,"c":33333,"d":444454,"e":55555555},
    "last":[
          {
            "id": 8817,
            "loc": "NEW YORK CITY"
          },
          {
            "id": 2873,
            "loc": "UNITED STATES"
          },
          {
            "id": 1501,
            "loc": "NEW YORK STATE"
          }
        ]
    }';
    
    
    $php = json_decode($json, true);
    echo var_export($php);
    

    prints

    array (
      'aaa' => 1,
      'b' => 2,
      'c' => 3,
      'd' => 4,
      'e' => 5,
      'fff' => 
      array (
        'a' => 11111,
        'b' => 222222,
        'c' => 33333,
        'd' => 444454,
        'e' => 55555555,
      ),
      'last' => 
      array (
        0 => 
        array (
          'id' => 8817,
          'loc' => 'NEW YORK CITY',
        ),
        1 => 
        array (
          'id' => 2873,
          'loc' => 'UNITED STATES',
        ),
        2 => 
        array (
          'id' => 1501,
          'loc' => 'NEW YORK STATE',
        ),
      ),
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some PHP code that outputs a JSON array when $.getJSON is called:
I have this swf (flash) file that provides the json that needs to be
I have a web service that queries data from this json file, but I
I have to process JSON files that looks like this: \u0432\u043b\u0430\u0434\u043e\u043c <b>\u043f\u0443\u0442\u0438\u043c<\/b> \u043d\u0430\u0447 Unfortunately,
I understood that this Bind attribute was not necessary, but JSON type is not
https://search.twitter.com/search.json?q=doug How do I read this like VIEW SOURCE, so that I know what
I have a JSon array that displays in a JQuery Mobile list. It shows
This is my code: <?php require_once '../../../jq-config.php'; // include the jqGrid Class require_once ABSPATH.php/jqGrid.php;
I just read this: http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx I was under the impression that overwriting Object or
I'm getting this json string info from the server : {members:[[sd2840d,Johny],[jkld341,Marry]]} So I store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.