I'm trying to create JSON arrays to postback to them to Slack with info from a while loop.
Here is the code I've came up with:
$adset = null;
while ($row = mysqli_fetch_array($leadsAdsetsQuery)) {
if ($row["adset"] != $adset) {
$adset = $row["adset"];
echo "{$adset}<br>";
}
echo $row["id"] . "<br>";
}
The output is:
Adset Name 1
20
Adset Name 2
34
Adset Name 3
11
And I need to have a new JSON array for each Adset Name with the number of leads structure like this:
'attachments' =>
array (
0 =>
array (
'fallback' => 'XXX',
'text' => 'XXX',
'fields' =>
array (
0 =>
array (
'title' => 'Adset Name 1',
'value' => '20',
'short' => true,
),
1 =>
array (
'title' => 'Adset Name 2',
'value' => '34',
'short' => true,
),
2 =>
array (
'title' => 'Adset Name 3',
'value' => '11',
'short' => true,
),
),
'color' => '#F35A00',
),
)
I'm not a big expert in JSON nor in PHP and google didn't seem to help.