pixeloft pixeloft - 1 year ago 74
JSON Question

PHP append each element in an array

I'm having a difficult time appending each element in an array I have in PHP for multiple OneSignal tags. Here is the result of my current JSON encoded array:


Desired output:


Here is my current PHP code:

$jsonData = array();

$allStaffInit = mysql_query("Select * from users");

while ($staffrow = mysql_fetch_object($allStaffInit)){

$jsonData[] = $staffrow;


echo json_encode($jsonData);

Any help is greatly appreciated! Thanks!

Answer Source

Try replacing

$jsonData[] = $staffrow;


$object = new stdClass();
$object->key = "user_email";
$object->relation = "=";
$object->value = $staffrow->value;

$jsonData[] = $object;

I am typing this in a browser, so cannot test, but you get the idea (if you don't get the idea, ask in comments :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download