0

i've been trying to make this array

$data = array (
    'country' => '+57',
    'message' => 'test',
    'messageFormat' => 0,
    'addresseeList' => 
    array (
      0 => 
      array (
        'mobile' => '1111',
        'correlationLabel' => 'corelation ejemplo',
      ),
    )
    );

into this

$data = array();

      $data['country'] = '+57';
      $data['message'] = 'test';
      $data['messageFormat'] = 0;
      $data['addresseeList'] = array(
        
          $data['mobile'] = '1111',
          $data['correlationLabel'] = 'corelation ejemplo'
      
      );

But when i try to convert this array into a json object i'm getting this

string(154) "{"country":"+57","message":"test","messageFormat":0,"mobile":"1111","correlationLabel":"corelation ejemplo","addresseeList":["1111","corelation ejemplo"]}"

but i should get something like this

string(128) "{"country":"+57","message":"test","messageFormat":0,"addresseeList":[{"mobile":"1111","correlationLabel":"corelation ejemplo"}]}"

Thanks in advance

0

1 Answer 1

0

The way you are inserting the address info actually places the mobile and correlationLabel at the root of the $data array.

instead, you need to add create an entirely new array to place as the only element inside an array you create at $data['addresseeList'].

$data = array();

$data['country'] = '+57';
$data['message'] = 'test';
$data['messageFormat'] = 0;
$data['addresseeList'][] = array(
    'mobile' => '1111',
    'correlationLabel' => 'corelation ejemplo'
);

echo json_encode($data, JSON_PRETTY_PRINT).PHP_EOL;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.