Jump to content

array_merge help


petroz

Recommended Posts

Hi Guys,

 

Been a while since I've done this and I cant seem to get it right. I am using an array to create a dropdown menu. The first array is all options, and the second array is the selected option.

 

Here is the code I am using to merge the arrays.

//create the dropdown
$possible_pages = $this->admin_model->page_dropdown();
$current_page = $this->admin_model->current_page_dropdown($page_id);
$data['pages_dropdown'] = array_merge($current_page, $possible_pages);

 

The result I am getting seems to be reseting the keys in the array, which will not work as intended. Please point me in the right direction to get this array to look as intended the in the example below.

 

I would like the array to look like...

Array ([8] => VPO's [7] => CPO's [8] => VPO's)

 

Here are the arrays...

Array ( [7] => CPO's [8] => VPO's ) 
Array ( [8] => VPO's )

 

This is the result I am getting now.

Array ( [0] => VPO's [1] => CPO's [2] => VPO's )

 

 

Link to comment
Share on other sites

Hi btherl,

 

Thanks for the reply. I just tried using the union operator. But its not working. Take a look below

 

The revised code...

//create the dropdown
$possible_pages = $this->admin_model->page_dropdown();
$current_page = $this->admin_model->current_page_dropdown($page_id);
$data['pages_dropdown'] = array_merge($current_page + $possible_pages);

 

I also tried this... and I get the same result as the above code...

$data['pages_dropdown'] = $current_page + $possible_pages;

Result..

Array ( [8] => VPO's [7] => CPO's )

 

Thanks Again for the reply!

Link to comment
Share on other sites

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.