/    Sign up×
Community /Pin to ProfileBookmark

Multidimensional JavaScript Array to PHP array

[code=html]I have been trying to figure this out for awhile. I have a multidimensional array in JavaScript that is 12 columns wide and an unknown number of rows like so<br />
/*<br />[<br />
[userID (int), name, username, email, password, other 1, other 2, other 3, other 4, other 5, other 6, admin(int)],<br />
[userID (int), name, username, email, password, other 1, other 2, other 3, other 4, other 5, other 6, admin(int)],<br />
[userID (int), name, username, email, password, other 1, other 2, other 3, other 4, other 5, other 6, admin(int)],<br />
…]<br />
*/<br />

All the values are string except the (int) ones. This is for a real time user editing page for my site. I have the JavaScript array made now I need it so when the “Submit” button is pressed it turns the array formated like that into an PHP array and saves it as a variable. Can I get some help?[/code]

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@angellus_mortisauthorFeb 17.2010 — Sorry about that. Here it is better.

I have been trying to figure this out for awhile. I have a multidimensional array in JavaScript that is 12 columns wide and an unknown number of rows like so<br />

/*<br />[<br />

[userID (int), name, username, email, password, other 1, other 2, other 3, other 4, other 5, other 6, admin(int)],<br />

[userID (int), name, username, email, password, other 1, other 2, other 3, other 4, other 5, other 6, admin(int)],<br />

[userID (int), name, username, email, password, other 1, other 2, other 3, other 4, other 5, other 6, admin(int)],<br />

...]<br />

*
/<br />

All the values are string except the (int) ones. This is for a real time user editing page for my site. I have the JavaScript array made now I need it so when the "Submit" button is pressed it turns the array formated like that into an PHP array and saves it as a variable. Can I get some help?
Copy linkTweet thisAlerts:
@demodavFeb 25.2010 — I'm working on the same thing. I know in theory how to do it but haven't found proper code yet.

Lets say you have a javascript file .js you can open that file with php loop through the file and create your php code from your file. Please post code if anybody finds a solution.

My array is as follows


var Chapter1 = [["Text", "page", 0,

["Text", "page", 0,

["Text", "page", 0,

["Text", "page", 0],

["Text", "page", 0,

["Text", "page", 0],

["Text", "page", 0],

["Text", "page", 0],

],

My company sends me a giant javascript for a tree navigation but it's all on one line. I'm trying to figure out a nice method to properly tab these for readability.

var Chapter1 = [["Text", "page", 0,

["Text", "page", 0,

["Text", "page", 0,

["Text", "page", 0],

["Text", "page", 0,

["Text", "page", 0],

["Text", "page", 0],

["Text", "page", 0],

],
Copy linkTweet thisAlerts:
@demodavFeb 25.2010 — Ok I see spacing doesn't work so here it is again hopefully

var Chapter1 = [["Text", "page", 0,

[INDENT][INDENT]["Text", "page", 0,[/INDENT][/INDENT]

[INDENT][INDENT][INDENT]["Text", "page", 0,[/INDENT][/INDENT][/INDENT]

[INDENT][INDENT][INDENT][INDENT]["Text", "page", 0],[/INDENT][/INDENT][/INDENT][/INDENT]

[INDENT][INDENT][INDENT]["Text", "page", 0,[/INDENT][/INDENT][/INDENT]

[INDENT][INDENT][INDENT][INDENT]["Text", "page", 0],[/INDENT][/INDENT][/INDENT][/INDENT]

[INDENT][INDENT][INDENT][INDENT]["Text", "page", 0],[/INDENT][/INDENT][/INDENT][/INDENT]

[INDENT][INDENT][INDENT][INDENT]["Text", "page", 0],[/INDENT][/INDENT][/INDENT][/INDENT]

],
Copy linkTweet thisAlerts:
@rnd_meFeb 25.2010 — 

My company sends me a giant javascript for a tree navigation but it's all on one line. I'm trying to figure out a nice method to properly tab these for readability.[/QUOTE]


[CODE]JSON.stringify(objToView, null "t");[/CODE]
Copy linkTweet thisAlerts:
@angellus_mortisauthorFeb 26.2010 — Sorry, kind of a n00b here. How does that work?
Copy linkTweet thisAlerts:
@demodavFeb 26.2010 — How would that be done via PHP? and if should I use Zend/Json? or would it be done Javascript?

It's got to be PHP to regenerate file correct?
Copy linkTweet thisAlerts:
@rnd_meFeb 26.2010 — in php, use jaon_encode() to turn a php array (assoc or reg) into JSON.

you can change it back using json_decode().

on the client side, the corresponding functions are JSON.stringify(), and JSON.parse()

I'm not a php guy, but i think you can use an optional argument to json_encode() to format the JSON, just like you can with JSON.stringify().
×

Success!

Help @angellus_mortis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...