Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP to Javascript: 2D array conversion

Status
Not open for further replies.

ruffy

Programmer
Oct 1, 2003
72
US
I've got a 2D array in PHP that looks like this:
$pi = 0;
$pf[$pi][0] = 0;
$pf[$pi][1] = 0;
$pf[$pi][2] = 1;
$pf[$pi][3] = 1;
$pf[$pi][4] = "Johnny come lately";
$pf[$pi][5] = 7;
$pi++;
$pf[$pi][0] = 0;
$pf[$pi][1] = 0;
$pf[$pi][2] = 1;
$pf[$pi][3] = 2;
$pf[$pi][4] = "Peter Pan went to town";
$pf[$pi][5] = 14;
$pi++;
$pf[$pi][0] = 0;
$pf[$pi][1] = 0;
$pf[$pi][2] = 1;
$pf[$pi][3] = 3;
$pf[$pi][4] = "The elf was weaned";
$pf[$pi][5] = 6;

ETC

How do I get this array into javascript so I can therein manipulate it?
Thanks for your time - Meir



 
faq434-1222

To err is human, to completely mess up takes a computer. [morning]
 
Using hidden fields in a form or generating array's javascript code on the fly.Like...
Code:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>

<html>
<head>
<title>Untitled</title>
</head>
<body>
<? 
$pi = 0;
$pf[$pi][0] = 0;
$pf[$pi][1] = 0;
$pf[$pi][2] = 1;
$pf[$pi][3] = 1;
$pf[$pi][4] = &quot;Johnny come lately&quot;;
$pf[$pi][5] = 7;
$pi++;
$pf[$pi][0] = 0;
$pf[$pi][1] = 0;
$pf[$pi][2] = 1;
$pf[$pi][3] = 2;
$pf[$pi][4] = &quot;Peter Pan went to town&quot;;
$pf[$pi][5] = 14;
$pi++;
$pf[$pi][0] = 0;
$pf[$pi][1] = 0;
$pf[$pi][2] = 1;
$pf[$pi][3] = 3;
$pf[$pi][4] = &quot;The elf was weaned&quot;;
$pf[$pi][5] = 6;
?>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>
pf = new Array();
<? foreach($pf as $key => $value) { 
    foreach($value as $key2 => $value2) {?>
     pf[<? print $key ?>][<? print $key2 ?>] = &quot;<? print &quot;$value2&quot; ?>&quot;;<?
    }
	 }		
?>
</script>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top