Answer the question
In order to leave comments, you need to log in
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]);
}
$json[] = array(
'uuid' => date('YmdHis'),
'goods' => $description1
);
$json = json_encode($json, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_NUMERIC_CHECK);
[{"uuid":"20190922163205","goods":}]
, [{"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}]}]
Answer the question
In order to leave comments, you need to log in
$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 questionAsk a Question
731 491 924 answers to any question