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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:51:42+00:00 2026-05-29T11:51:42+00:00

I am learning json now and have run into an issue: I am using

  • 0

I am learning json now and have run into an issue:

I am using code like this to spit about and array of data:

<?php
 $requiredFieldsArray = array();
    $results = mysql_query("select account_id, display_name, id from field 
where account_id = $holdAcctID and required_flag = 1");
    while($result = mysql_fetch_assoc($results)) 
        {
        $requiredFieldsArray[] = $result;
    }
?>
<script language="javascript">
    var requiredFieldsPRS = <?php echo "new Array(". json_encode($requiredFieldsArray).")"; ?>;
</script>
}

It outputs this:

 var requiedFieldsPRS = new Array([{"account_id":"3","display_name":"Project Requested By","id":"15"},{"account_id":"3","display_name":"Project Title","id":"18"},{"account_id":"3","display_name":"Project Type","id":"19"},{"account_id":"3","display_name":"Banner Details","id":"20"},{"account_id":"3","display_name":"Email to Me","id":"2910"}]);;

In my code how can I remove the “[” and “]” from the beginning and end of the array, so it will appear like this?

var requiedFieldsPRS = new Array({"account_id":"3","display_name":"Project Requested By","id":"15"},{"account_id":"3","display_name":"Project Title","id":"18"},{"account_id":"3","display_name":"Project Type","id":"19"},{"account_id":"3","display_name":"Banner Details","id":"20"},{"account_id":"3","display_name":"Email to Me","id":"2910"});

Note: The opening and closing brackets are gone in the above output.

  • 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-29T11:51:44+00:00Added an answer on May 29, 2026 at 11:51 am

    You can trim off leading and ending []s easily enough for this particular example:

    var requiredFieldsPRS = <?php echo "new Array(". trim(json_encode($requiredFieldsArray), '[]').")"; ?>;
    

    However if your Array constructor is not necessary you could just use:

    var requiredFieldsPRS = <?php echo json_encode($requiredFieldsArray); ?>;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning python and i loop like this the json converted to dictionary: it
This is my first time learning json and this is my sample code: $(function
I'm just learning json. I'm trying to create an array of object Messages, The
This is my json response {COLUMNS:[LABEL1, LABEL2, RATE1, RATE2], DATA:[[tps, tvq, 10.0, 20.0]]} And
I've been learning Php/SQL/JSON for just over 24 hours now and its gone pretty
I've been learning how to parse JSON using the JSON framework and ASIHTTPRequest for
Hi I am still learning this JSON stuff... I think I found a valid
I'm just learning about ORM's, and am wondering... if you have an object (a
I'm trying to get my jQuery to work in this flow: Parse json using
I've just started learning about parsing, and I wrote this simple parser in Haskell

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.