# Array comparison problem

**URL:** <https://forum.kirupa.com/t/array-comparison-problem/295741>\
**Category:** programming\
**Created:** [September 3, 2009, 5:26pm UTC](https://forum.kirupa.com/t/array-comparison-problem/295741 "2009-09-03T17:26:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ximenao](https://avatars.discourse-cdn.com/v4/letter/x/eada6e/32.png) [@Ximenao](https://forum.kirupa.com/u/Ximenao)\
**Post date:** [September 3, 2009, 5:26pm UTC](https://forum.kirupa.com/t/array-comparison-problem/295741/1 "2009-09-03T17:26:25Z")

</div>

It’s been awhile since I posted on these forums  
but now I have a rather complicated problem and I’m hoping anyone can help me:  
I’m trying to code a testing system, where the user will enter data into a HTML form, which posts it to a PHP script  
which is supposed to compare the entered data with the correct data stored within a XML file.  
The php page is supposed to echo which os the answers are right and which are wrong, using array\_diff() and array\_intersect()  
The PHP code itself looks something like this:

\*\<?php  
$exercise = $\_POST[‘exercise’];  
$nose = $\_POST[‘nose’];  
$gold = $\_POST[‘gold’];  
$black = $\_POST[‘black’];  
$northwest = $\_POST[‘northwest’];  
$character = $\_POST[‘character’];  
$chicken = $\_POST[‘chicken’];  
$tomarket = $\_POST[‘tomarket’];  
$translate= array (0 =\> Array($exercise), 1 =\> Array($nose), 2 =\> Array($gold), 3 =\> Array($black), 4 =\> Array($northwest), 5 =\> Array($character), 6 =\> Array($chicken), 7 =\> Array($tomarket));  
$dom =  
domxml\_open\_mem(file\_get\_contents(‘test\_2.xml’));

foreach ($dom-\>get\_elements\_by\_tagname(‘palabra’) as  
$element) {  
$attr = $element-\>attributes();  
foreach ($element-\>child\_nodes() as $e) {  
if (isset($e-\>tagname)) {  
if ($e-\>tagname == ‘uno’) {  
$node = $e-\>first\_child();  
$uno = htmlspecialchars  
($node-\>node\_value());  
} elseif ($e-\>tagname == ‘dos’) {  
$node = $e-\>first\_child();  
$dos =  
htmlspecialchars($node-\>node\_value());  
} elseif ($e-\>tagname == ‘tres’) {  
$node = $e-\>first\_child();  
$tres =  
htmlspecialchars($node-\>node\_value());  
} elseif ($e-\>tagname == ‘cuatro’) {  
$node = $e-\>first\_child();  
$cuatro =  
htmlspecialchars($node-\>node\_value());  
} elseif ($e-\>tagname == ‘cinco’) {  
$node = $e-\>first\_child();  
$cinco =  
htmlspecialchars($node-\>node\_value());  
} elseif ($e-\>tagname == ‘seis’) {  
$node = $e-\>first\_child();  
$seis =  
htmlspecialchars($node-\>node\_value());  
} elseif ($e-\>tagname == ‘siete’) {  
$node = $e-\>first\_child();  
$siete =  
htmlspecialchars($node-\>node\_value());  
} elseif ($e-\>tagname == ‘ocho’) {  
$node = $e-\>first\_child();  
$ocho =  
htmlspecialchars($node-\>node\_value());  
}  
}  
}  
$spanish= array (a =\> Array($uno), b =\> Array($dos), c =\> Array($tres), d =\> Array($cuatro), e =\> Array($cinco), f =\> Array($seis), g =\> Array($siete), h =\> Array($ocho));  
$correct = array\_intersect($translate, $spanish);  
$wrong = array\_diff($translate, $spanish);  
echo “\<p\>You got the following words correct: \<font color “00FF00”\>”;  
echo print\_r ($correct);  
echo “\</font\>\</p\>”;  
echo “\<p\>But you got these words wrong!: \<font color “FF0000”\>”;  
echo print\_r ($wrong);  
echo “\</font\>\</p\>”;

}  
?\>\*

However the array comparison functions don’t seem to be working;  
Can anyone please tell me why? Is there some syntax error I’m making?
