S
S
SARCASM742021-01-11 09:20:49
PHP
SARCASM74, 2021-01-11 09:20:49

How to create json array with another array?

Hello Uv. Experts ask for your help.
You need to create a JSON array so that the output would look like this:

users: (6) [{"id":1,"login":'Admin'}, null, null, null, null, null]
route: true
spectators: null

Only in users: (6) the number will change, and you still need to substitute data in a different key, i.e. if you register another user, then you need to do something like this:
users: (6) [{"id":1,"login":'Admin'}, {"id":2,"login":'NickLogin'}, null, null, null, null]

Many thanks in advance. All good!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Slava Rozhnev, 2021-01-11
@SARCASM74

The following PHP array is converted into the JSON you need:

<?php
$json = [
  [
    ["id"=>1,
     "login"=>'Admin'
    ], 
    null, 
    null, 
    null, 
    null, 
    null
  ],
  'route' => true,
  'spectators' => null
];

echo json_encode($json);

Check PHP code here

M
my lord, 2021-01-11
@XBEHOLI

[
    "Что-то" => [
         "gg" => "otvet",
         "tt" => "minet:d"
     ]
]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question