Jump to content

Bah, Problems with my multi dimensional array.


yanjchan

Recommended Posts

Sorry for this short intro, but I'm a bit short on time.

I keep getting an error whenever I try this; can someone please help me?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$answers = array(
			 array(
						//2+2 is what!!!
						'isdisputed'	=>	'yes',
						'answers'	=>	array(
													  
												'1' => array(
																				  'propnum'	=>	'4',
																				  'grades'	=>	'84,98,42,67',
																				  'answer'	=>	'5'
																				  )
												'2' => array(
																				  'propnum'	=>	'10',
																				  'grades'	=>	'100,98,99,86,86,20,86,100,100,100',
																				  'answer'	=>	'4'
																				  )
														)
						)
$xw = new xmlWriter();
$xw->openMemory(); //use openUri() to output directly to a file
$xw->startDocument('1.0', 'UTF-8');
$xw->startElement('share');
$xw->writeElement('page', 'page#');
$xw->writeElement('numsequence', 'numseq');
$xw->writeElement('publisher', 'pub');
$xw->writeElement('book', 'bookname');
foreach ($answers as $answer)
{
$xw->startElement('answer');
// $xw->writeElement('answernumber', $answer);
$xw->writeElement('isdisputed', $answer['isdisputed']);
	foreach ($answers['answers'] as $disputedanswer)
	{
		$xw->startElement('disputedanswer');
		$xw->writeElement('supporters', $disputedanswer['propnum']);
		$xw->writeElement('grades', $disputedanswer['grades']);
		$xw->writeElement('answer', $disputedanswer['answer']);
		$xw->endElement();
	}
}
$xw->endElement(); //item

echo $xw;
?>
</body>
</html>

 

Thanks in advance

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$answers = array(
             array(
                     //2+2 is what!!!
                     'isdisputed'   =>   'yes',
                     'answers'   =>   array(
                                            
                                       '1' => array(
                                                                 'propnum'   =>   '4',
                                                                 'grades'   =>   '84,98,42,67',
                                                                 'answer'   =>   '5'
                                                                 ),
                                       '2' => array(
                                                                 'propnum'   =>   '10',
                                                                 'grades'   =>   '100,98,99,86,86,20,86,100,100,100',
                                                                 'answer'   =>   '4'
                                                                 )
                                             )
                     )
);
$xw = new xmlWriter();
$xw->openMemory(); //use openUri() to output directly to a file
$xw->startDocument('1.0', 'UTF-8');
$xw->startElement('share');
$xw->writeElement('page', 'page#');
$xw->writeElement('numsequence', 'numseq');
$xw->writeElement('publisher', 'pub');
$xw->writeElement('book', 'bookname');
foreach ($answers as $answer)
{
   $xw->startElement('answer');
   // $xw->writeElement('answernumber', $answer);
   $xw->writeElement('isdisputed', $answer['isdisputed']);
      foreach ($answers['answers'] as $disputedanswer)
      {
         $xw->startElement('disputedanswer');
         $xw->writeElement('supporters', $disputedanswer['propnum']);
         $xw->writeElement('grades', $disputedanswer['grades']);
         $xw->writeElement('answer', $disputedanswer['answer']);
         $xw->endElement();
      }
}
   $xw->endElement(); //item
   
   echo $xw;
   ?>
</body>
</html>

You don't know how monumentally thankful I am. :D

Thank you, thank you, thank you, thank you! Thank you! Thank you, Thank you!

 

A side question that I hope you won't mind:

 

Is it possible to get XMLWriter to output in a human-reading-friendly format?

 

Thanks!!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.