Jump to content

Adding items to an array


redbrad0

Recommended Posts

I know you can use array_push to add items to an array, but what can you use when everything is dynamic?

 

Example:

$order = array('Order_ID'=>$Order_ID,'Order_Status'=>$Order_Status,'Order_Date'=>$Order_Date);

$order_2 = array('Order_ChargedFrom'=>$Order_ChargedFrom,'Order_TotalOrderAmount'=>$Order_TotalOrderAmount);

foreach ($order_2 as $k => $v) {
  // Need to add the name ($k) and the value ($v) to array $order
  // ??????????
}

Link to comment
https://forums.phpfreaks.com/topic/97123-adding-items-to-an-array/
Share on other sites

following your style, you could use:

 

<?php
$order = array('Order_ID'=>$Order_ID,'Order_Status'=>$Order_Status,'Order_Date'=>$Order_Date);
$order_2 = array('Order_ChargedFrom'=>$Order_ChargedFrom,'Order_TotalOrderAmount'=>$Order_TotalOrderAmount);
foreach ($order_2 as $k => $v) {
  $order[$k] = $v;
}
?>

but it's easier to do this:

<?php
$order = array('Order_ID'=>$Order_ID,'Order_Status'=>$Order_Status,'Order_Date'=>$Order_Date);
$order_2 = array('Order_ChargedFrom'=>$Order_ChargedFrom,'Order_TotalOrderAmount'=>$Order_TotalOrderAmount);
$order = array_merge($order,$order_2);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.