I have an array like this:
$itemID = [
"appid" => 570,
"contextid" => "2",
"amount" => 1,
"assetid" => $value
];
I want to make another array which contains different $itemIDs because $value will keep changing.
I'm trying to use array_push like this:
$itemsID = [ ];
array_push($itemsID, $itemID);
the output is:
Array
(
[0] => Array
(
[appid] => 570
[contextid] => 2
[amount] => 1
[assetid] => 5628263595
)
)
Array
(
[0] => Array
(
[appid] => 570
[contextid] => 2
[amount] => 1
[assetid] => 3651140937
)
)
I want the output to be:
Array
(
[0] => Array
(
[appid] => 570
[contextid] => 2
[amount] => 1
[assetid] => 5628263595
[1] => Array
(
[appid] => 570
[contextid] => 2
[amount] => 1
[assetid] => 3651140937
)
how can I achieve this?
full code:
foreach ($select as $key => $value) {
if(array_key_exists($key, $select)) {
$itemID = [ "appid" => 570,
"contextid" => "2",
"amount" => 1,
"assetid" => $value ];
$itemsID = [ ];
array_push($itemsID, $itemID);
echo "<pre>";
print_r($itemsID);
echo "</pre>";
}
}