Essentially I have the following conditionals that are made to assemble an array - the issue is the array it currently creating has too many objects.
$a = 1
$b = 2
if ($a == 1)){
$results[]['id'] = 5;
$results[]['reasons'] = "A issue";
}
if ($b == 1){
$results[]['id'] = 6;
$results[]['reasons'] = "B issue";
}
if ($b == 2){
$results[]['id'] = 6;
$results[]['reasons'] = "B issue";
}
)
$json = json_encode(array($results));
echo $json;
Current Result:
[
{
"id": 5
},
{
"reasons": "A issue"
},
{
"id": 6
},
{
"reasons": "B issue"
}
]
What I need:
[
{
"id": 5,
"reasons": "A issue"
},
{
"id": 6,
"reasons": "B issue"
}
]
How can this JSON Array be built correctly using the conditionals?
$bis 1 or 2) to reduce duplication of code if you can.