I have two different sized arrays and want to display them side by side in the same table.
I tried to run both arrays in a loop but the issue is the shorter array runs out of index.
Here's what I tried:
$clean_s = ['apple','ball','cat','dog'];
$clean_r = ['apple','bat','carrot','duck','elephant','fan'];
if(sizeof($clean_s) == sizeof($clean_r)) {
$max = sizeof($clean_s);
} else {
$max = sizeof($clean_s) > sizeof($clean_r) ? sizeof($clean_s) : sizeof($clean_r);
}
$table = '<table><thead><tr><th>Source</th><th>Result</th></thead><tbody>';
for($i=0; $i < $max; $i++) {
$table .= '<tr><td>'.$clean_s[$i].'</td><td>'.$clean_r[$i].'</td></tr>';
}
Output needed:
Source | Result
________________________
apple | apple
ball | bat
cat | carrot
dog | duck
| elephant
| fan