Jump to content

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);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.