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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:18:05+00:00 2026-05-24T02:18:05+00:00

I was trying to find an answer for this question for a while but

  • 0

I was trying to find an answer for this question for a while but no luck.

The problem is this. On one PHP page i have multiple javascript arrays (lets say 2). One of those arrays is an array that represents pieces of a shirt and the other array contains color of each piece.

  $pieces[0] = 'base';
  $pieces[1] = 'sleeves';
  $pieces[2] = 'pocket';

  $colors[0] = 'white';
  $colors[1] = 'red';
  $colors[2] = 'black';

On top of all that i have a form with where user can enter some data.

Now my question is, how can I pass those two arrays and form data to a PHP page?

Thanks for all your help.

/******
EDIT

******/

Well in case that someone has the same problem the solution is to serialize the arrays, insert them in a hidden field on a form and deserialize it on a PHP page

http://code.activestate.com/recipes/414334-pass-javascript-arrays-to-php/

  • 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-24T02:18:06+00:00Added an answer on May 24, 2026 at 2:18 am

    I am not sure if I get your question as you appear to have listed a PHP array there and not a Javascript one.

    Passing as one array from JS

    var pieces = [
        "base",
        "sleeves",
        "pocket"
    ];
    var colors = [
        "white",
        "red",
        "black"
    ];
    var send_array = {
        "colors": colors,
        "pieces": pieces
    };
    $.post('/my/url.php', send_array); //using jQuery for ajax request
    

    Extracting json array in PHP

    $send_array = json_decode($json, true);  
    

    Passing as one array from PHP to JS

    $pieces[0] = 'base';
    $pieces[1] = 'sleeves';
    $pieces[2] = 'pocket';
    
    $colors[0] = 'white';
    $colors[1] = 'red';
    $colors[2] = 'black';
    
    $send_array = array(
        'colors' => $colors,
        'pieces' => $pieces,
    );
    $json = json_encode($send_array);  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been searching around trying to find an answer to this question, and I
I was trying to find this answer on Google, but I guess the symbol
I'm sure this is a very stupid question but I can't find the answer,
I'm trying to find an answer for a problem my developers are having. I
While trying to implement the second answer to a previous question , I am
I can't seem to find an answer to this question or a good example
I did a fair bit of searching for an answer to this question, but
Over the past few days, I have been trying to find an answer to
Quick and should be simple question, but i cant find the answer!!! So im
I know this is a very simple question but I have been struggling with

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.