0

Im having trouble trying to code this in PHP:

{
   "value": {
          "board": [
                  {"name": "Abdul-Jabbar", "values": [38387, 1560, 24.6]},
                  {"name": "Karl Malone", "values": [36928, 1476, 25.0]},
                  {"name": "Michael Jordan", "values": [32292, 1072, 30.1]},
                  {"name": "W. Chamberlain", "values": [31419, 1045, 30.1]},
                  {"name": "Kobe Bryant", "values": [29484, 1161, 25.4]},
                  {"name": "Shaq O Neal", "values": [28596, 1207, 23.7]},
                  {"name": "Moses Malone", "values": [27409, 1329, 20.6]},
                  {"name": "Elvis Hayes", "values": [28313, 1303, 21.0]},
                  {"name": "H. Olajuwon", "values": [26946, 1238, 21.8]}
                  ]
            }
}

So far I have this:

  $cart = array();

  foreach ($deliveries as $delivery) {

    // get name of the message sent.
    $msgFilter = array('id' => $delivery->messageId);
    $message = array_pop($client->readMessages(array('pageNumber' => 1,
                             'includeContent' => false,
                             'filter' => $msgFilter))->return);



   $cart[] = array(
    "value" => array(
        array(
            "message" => $message->name
        ),
        array(
            "value" => $delivery->revenue
        )
    )
  );


  }

  $postData = json_encode($cart);

I cant figure out how to wrap value and board around the array?!?

2
  • 1
    The php json_decode function might help... Commented Oct 25, 2013 at 3:56
  • Refer this - w3schools.com/php/php_arrays_multi.asp, hope it helps Commented Oct 25, 2013 at 3:57

1 Answer 1

1

your code is kinda confusing to me the to-be-made array is actually an object/array mixture in sense of json a better represention would be

value.board.array_part

if you just want to wrap the cart array with board and value arrays

$board = array("board"=>$cart);
$val = array("value"=> $board);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you - Im actually quite confused too, thats why I posted on here!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.