I want to be build logic as with below desired result. I have multi arrays which to be listed in table as questionnaire along with skip approach.
Helps are definitely appreciated
Fiddle link also mentioned it :- PhpFiddle - PHP/MySQL in-browser IDE and online server
<?php
$users = array (
0 => array("user_id" => "217", "user_name" => "S", "id" => "33"),
1 => array("user_id" => "216", "user_name" => "A", "id" => "32"),
2 => array("user_id" => "215", "user_name" => "B", "id" => "31"),
);
$questions = array (
0 => array("text" => "Q1", "type" => "text", "qid" => "1"),
1 => array("text" => "Q2", "type" => "text", "qid" => "2"),
2 => array("text" => "Q3", "type" => "text", "qid" => "3"),
);
$answers = array (
0 => array("SRI" => "31", "qid" => "1", "answer" => "A1"),
1 => array("SRI" => "31", "qid" => "2", "answer" => "A2"),
2 => array("SRI" => "31", "qid" => "3", "answer" => "A3"),
3 => array("SRI" => "32", "qid" => "3", "answer" => "A3"),
4 => array("SRI" => "32", "qid" => "2", "answer" => "A2"),
5 => array("SRI" => "33", "qid" => "1", "answer" => "A1"),
6 => array("SRI" => "33", "qid" => "3", "answer" => "A3")
);
//echo "<pre>";
//print_r($users);
//print_r($questions);
//print_r($answers);
?>
<table border = 1>
<tr>
<th>
User
</th>
<?php
foreach($questions as $key => $Qval){
echo "<th>".$Qval['text']."</th>";
}
?>
</tr>
<?php
foreach($users as $key => $Uval){
echo "<tr>";
echo "<td>".$Uval['user_name']."</d>";
foreach($questions as $key => $Qval){
foreach($answers as $key => $Aval){
if (($Qval['qid'] == $Aval['qid']) && ($Uval['id'] == $Aval['SRI'])){
echo "<th>".$Aval['answer']."</th>";
}
}
}
echo "</tr>";
}
?>
</table>
Desired Result