Jump to content

array_combine modification


jjfletch

Recommended Posts

Is there a way to have the effect of array_combined, but ensure that duplicate elements of an array are not removed?


For example, the way things are now, this happens:


[code=php:0]Array ( [name] => Array ( [0] => Joe [1] => Joe [2] => Joe ) [animal] => Array ( [0] => Dog  [1] => Cat [2] => Rabbit  ) [submit] => Validez )
[/code]

Returns:


[code=php:0]Array ( [Joe] => Dog [] => )[/code]


What I would want is for it to return:


[code=php:0]Array ( [Joe] => Dog [Joe] => Cat  [Joe] => Rabbit)[/code]


Upon array_combine. 

This is the array_combine function I'm using:

[code=php:0]if (!function_exists('array_combine')) {
  function array_combine($a, $b) {
      $c = array();
      if (is_array($a) && is_array($b))
          while (list(, $va) = each($a))
              if (list(, $vb) = each($b))
                  $c[$va] = $vb;
              else
                  break 1;
      return $c;
  }
}
[/code]
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.