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

  • Home
  • SEARCH
  • 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 3602174
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:42:47+00:00 2026-05-18T20:42:47+00:00

This is how I got my php array to javascript echo ‘var daysofweek =

  • 0

This is how I got my php array to javascript

echo 'var daysofweek = '.json_encode($daysofweek).';';

Now I am aware that json_decode can do the opposite, however the problem is I don’t know the syntax to do so.

I tried:

<script>
var array_days = new Array();

array_days[] = "psdfo";
array_days[] = "bsdf";

<?php
$array_days = json_decode(?>array_days<?php);?>

</script>

yes im clueless.

I forgot to mention that I want to send an array through post, having all my information regarding all the form values dynamically created by javascript. Otherwise, I wouldn’t know which name=”” to look for as it will be decided by the user. Unless someone else has an alternative solution…

  • 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-18T20:42:48+00:00Added an answer on May 18, 2026 at 8:42 pm
    <script>
    var array_days = new Array();
    
    array_days[] = "psdfo";
    array_days[] = "bsdf";
    
    <?php
    $array_days = json_decode(?>array_days<?php);?>
    
    </script>
    

    I’m clueless in this part… is this javascript? if so, you need to use a JSON Parser like the JSON2.js https://github.com/douglascrockford/JSON-js

    this file creates a Javascript JSON Object which allows you to parse a JSON string to a Javascript object. (you can always use eval() but it won’t prevent against possible malicious code…) or the other way around… from a Javascript Object transform into a JSON string.

    After converting to a JSON string you just need to send the data through AJAX to a PHP file, like:

    var data = {
       key: value,
       key2: value2 
    },
    JSON = JSON.stringify(data);
    
    $.ajax({
        url: 'php_file.php',
        type: 'POST',
        data: JSON,
        success: function(data){
            alert(data)
        }
    });
    

    (I’m using jQuery to save some lines…)

    Then on the php_file.php you would have something like this:

    <?php 
        $json = json_decode($_POST['data']);
    
        foreach($json as $value){
           //Do something with it!
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.