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 7855549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:25:13+00:00 2026-06-02T20:25:13+00:00

I have json_encoded array that i would like to add to using php [{id:a,value:2},{id:b,value:2}]

  • 0

I have json_encoded array that i would like to add to using php

[{"id":"a","value":"2"},{"id":"b","value":"2"}]

I want to add the following to the array above:

array("id" => c, "value" => "3") 

I tried json_decode then trying to push the array into that but im confused on how to do that

  • 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-06-02T20:25:14+00:00Added an answer on June 2, 2026 at 8:25 pm

    Make sure you use json_decode in array mode rather than object mode:

    // Default: JSON is decoded as object
    $json_object = json_decode($json_string);
    
    // Pass true in the second argument to get an array instead
    $json_array = json_decode($json_string, true);
    
    // Push a new entry onto the end
    $json_array[] = array("id" => c, "value" => "3");
    
    // Re-encode JSON string, if needed
    $json_final_string = json_encode($json_array);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script that returns a json_encoded response that is like so:
I have a php file somejson.php that echos a json encoded array {jsonone:first json,jsontwo:second
I have a php file that is creating a array of everything in my
I am returning results from a MySql database in PHP that I would like
I have a JSON string (from PHP's json_encode() that looks like this: [{id: 1,
I am using Graph API https://developers.facebook.com/docs/reference/api/#publishing with PHP SDK and I would like to
I have a function that returns json (networks_function.php builds up some arrays and encodes
I have a multidimensional array, here: $noticeDate = json_encode( $noticesDates ); and I want
Does anyone know there have any other way that (by not using json_encode and
I have JSON text that looks like this: { ok: true, totalPages: 256, arReports:

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.