I have an multidimensional array from an XML file which I want to compare with a normal array. I need to compare the [tag] name in the multidimensional array with the name in the other array and get value from the multidimensional array that belongs to the tag.
Array
(
[0] => Array
(
[tag] => DOCUMENT
[type] => open
[level] => 1
)
[1] => Array
(
[tag] => SENDERID
[type] => complete
[level] => 2
[value] => TEST
)
[2] => Array
(
[tag] => SENDERSHORTNAME
[type] => complete
[level] => 2
)
[3] => Array
(
[tag] => RECIPIENTID
[type] => complete
[level] => 2
[value] => VGLEE
)
)
Second array which I need to compare it with the multidimensional array:
$compare_array = array('DOCUMENT', 'SENDERID', 'SENDERSHORTNAME', 'RECIPIENTID');
Now I want to check if the key from $compare_array is matched in the multidimensional array. If so, I want to grab the value from the multidimensional array and make a variable with the name from the compare_array and append the value to the variable.
I made a for loop:
for($i = 0; $i < $count; $i++){
if($values[$i]['tag'] == 'SENDERID'){
$SENDER = $values[$i]['value'];
}
if($values[$i]['tag'] == 'RECIPIENTID'){
$RECIPIENTID = $values[$i]['value'];
}
if($values[$i]['tag'] == 'IREF'){
$IREF = $values[$i]['value'];
}
if($values[$i]['tag'] == 'DOCUMENTNUMBER'){
$DOCUMENTNUMBER = $values[$i]['value'];
}
}