Web Analytics Made Easy -
StatCounter array_combine modification - CodingForum

Announcement

Collapse
No announcement yet.

array_combine modification

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • array_combine modification

    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:


    PHP Code:
    Array ( [name] => Array ( [0] => Joe [1] => Joe [2] => Joe ) [animal] => Array ( [0] => Dog  [1] => Cat [2] => Rabbit  ) [submit] => Validez 
    Returns:


    PHP Code:
    Array ( [Joe] => Dog [] => ) 

    What I would want is for it to return:


    PHP Code:
    Array ( [Joe] => Dog [Joe] => Cat  [Joe] => Rabbit

    Upon array_combine.

    This is the array_combine function I'm using:

    PHP Code:
    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;
       }


  • #2
    You can't assign more than one value to an array's index. If $array['Joe'] could equal 'Rabbit' and 'Dog' and 'Cat' at the same time, I think it would cause some sort of worm hole and the earth would implode.

    Comment

    Working...
    X