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 // ?????????? } Quote 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); ?> Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.