Forum Moderators: coopster

Message Too Old, No Replies

Converting Javascript array to PHP array?

         

zver0

1:07 pm on May 16, 2006 (gmt 0)

10+ Year Member



Is there a way to convert the following Javascript array to a multidimensional PHP array? I've been trying for a few hours and finally gave up. Hope some of the gurus here could help :)

Thanks in advance.

partial code - jatar_k

var p = new Array();
p[1005] = new Array();
p[1005]['n'] = '20 mg - 30 Tabs';
p[1005]['s'] = '4236691';
p[1005]['p'] = '$182.00';
p[1005]['b'] = 'example';
p[1005]['u'] = '$6.07';
p[1010] = new Array();
p[1010]['n'] = '20 mg - 60 Tabs';
p[1010]['s'] = '4236691';
p[1010]['p'] = '$327.00';
p[1010]['b'] = 'example';
p[1010]['u'] = '$5.45';
p[1015] = new Array();
p[1015]['n'] = '20 mg - 90 Tabs';
p[1015]['s'] = '4236691';
p[1015]['p'] = '$472.00';
p[1015]['b'] = 'example';
p[1015]['u'] = '$5.24';

there is a ton more after that

[edited by: jatar_k at 2:45 pm (utc) on May 16, 2006]
[edit reason] no urls thanks [/edit]

jatar_k

3:00 pm on May 16, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



to be honest it can almost be pasted directly into a php script

these lines

var p = new Array();
p[1005] = new Array();

would be this instead

$p = array();
$p[1005] = array();

and each mention of p should be $p instead

aside from throwing a ton of notices for 'previously undefined', which isn't a big deal, it should work

zver0

5:32 pm on May 16, 2006 (gmt 0)

10+ Year Member



Damn, I'm stupid :)

Thanks a lot Jatar_k, worked like a charm.