Answer the question
In order to leave comments, you need to log in
Comparing arrays and outputting to a table?
There is an array:
Array
(
[oldAttributes] => Array
(
[id] => 1
[city_id] => 5
[status] => 0
[name] => test1
)
[newAttributes] => Array
(
[id] => 1
[city_id] => 8
[status] => 0
[name] => test2
)
)
<table style="width: 100%;" border="1">
<thead>
<tr>
<td>Attribute</td>
<td>Value</td>
</tr>
</thead>
<tbody>
<?php if (!empty($params)) foreach ($params as $param => $val): ?>
<?php foreach ($val as $k => $v): ?>
<tr>
<td><?= $k ?></td>
<td><?= $v ?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
Answer the question
In order to leave comments, you need to log in
Inside :<tbody>
<?php
foreach ($params['oldAttributes'] as $oldName => $oldValue) {
$newValue = $params['newAttributes'][$oldName];
printf( "<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n",
$oldName,
$oldValue,
$newValue === $oldValue ? '' : $newValue
);
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question