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

Link to comment
Share on other sites

<!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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.