P
P
pr-Legolasov2019-09-22 16:55:29
PHP
pr-Legolasov, 2019-09-22 16:55:29

Multiple arrays instead of one?

Good day to all!
Faced with difficulty, I'm trying to add an object containing several arrays to an existing array, but it turns out that they are combined into one.

$resultcart =   DB::Query("SELECT * FROM buy WHERE number = '222'",$link);
     while($rowcart =  mysqli_fetch_array($resultcart))
        { 
          $description1[] = array(['good_uuid' => $rowcart["idprod"],
          'good_name' => $rowcart["name"], 
          'quantity' => $rowcart["quantity"],
          'price' => $rowcart["price"],
          'tag1214' => 4]);
          }

- from this you need to create an object containing several arrays
$json[] = array(
         'uuid' => date('YmdHis'),          
                 'goods' =>  $description1 
     );

- the actual array into which you need to insert the resulting arrays
As a result, after converting to json with this line
$json = json_encode($json, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);

i get the following:
[{"uuid":"20190922163205","goods":}]
,
but I need to get a string like this:
[{"uuid":"20190922163205","goods":[{"good_uuid":2,"good_name":"Конверт на выписку","quantity":1,"price":1,"tag1214":4}],[{"good_uuid":1,"good_name":"Звездная ночь на шампани","quantity":1,"price":1,"tag1214":4}]}]

How can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexalexes, 2019-09-22
@alexalexes

$description1[] = array([..................])
Pay attention to how many times an array is declared here in an array.
array([]) is the same as or array(array())
PS: In order not to be confused in the future, stop using one of the methods.
Either array() if you have php 5.6-
or [] if php 5.6+ (this is preferable - stylish, fashionable youth, similar to JS)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question