redbrad0 Posted March 20, 2008 Share Posted March 20, 2008 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 More sharing options...
rhodesa Posted March 20, 2008 Share Posted March 20, 2008 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); ?> Link to comment https://forums.phpfreaks.com/topic/97123-adding-items-to-an-array/#findComment-496985 Share on other sites More sharing options...
laffin Posted March 20, 2008 Share Posted March 20, 2008 i just use $order[] leaving the key index field blank, assigns it as next available index. Link to comment https://forums.phpfreaks.com/topic/97123-adding-items-to-an-array/#findComment-496986 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.