create an ajax json object from a simple indexed array

create an ajax json object from a simple indexed array

crush123crush123 Posts: 417Questions: 126Answers: 18

i am pulling in data from 2 different sources and using array_diff(array1, array2) to give me a simple indexed array like so...

Array ( [1] => email1@google.com [2] => email5@google.com [3] => email186@google.com ..)

i have tried json encoding this, but i can;t get it into a format that the datatable can read.

Grateful for any advice

(it may seem a pointless exercise, with a single column, but i am planning on using the email to do other stuff and an ajax source fits the bill

This question has an accepted answers - jump to answer

Answers

  • crush123crush123 Posts: 417Questions: 126Answers: 18
    edited November 2016 Answer ✓

    sorted it.

    i created a new array, looping through the array values, like this...

    $newarray = array();
    foreach ($oldarray as $value) {
    $newarray [] = [
    'Email' => $value,
    ];
    }

    the new array looks like this...

    Array ( [0] => Array ( [Email] => email1@google.com ) [1] => Array ( [Email] => email5@google.com ) [2] => Array ( [Email] =>email186@google.com ... )

    which i can json_encode for my datatable

    ;~)

This discussion has been closed.