Jump to content


Photo

array_combine


  • Please log in to reply
2 replies to this topic

#1 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 21 September 2006 - 02:09 PM

I am helping a friend and I need to combine 2 arrays. I know there is a simple function in php5 called array_combine. But he has php 4.x.x. Any one know a work around without having to install php5.

Thanks

Ray

#2 eric1235711

eric1235711
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts
  • LocationSão Paulo - Brazil

Posted 21 September 2006 - 02:30 PM

Isn´t you talking about merging? (array_merge)

you can make a function to combine... That´s not hard.
Programming is like building your own universe...
But let me ask you something:
Your world... It´s cool? Or it sucks?

#3 eric1235711

eric1235711
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts
  • LocationSão Paulo - Brazil

Posted 21 September 2006 - 02:42 PM

a very simple function to combine:

<?php

function ericsCombine($a1, $a2){
    $output = array();
    foreach($a1 as $key => $value){
        $output[$value] = $a2[$key];
    }
    return $output;
}

?>

or something like that...

You can work a little more on this function, it can get better...
Programming is like building your own universe...
But let me ask you something:
Your world... It´s cool? Or it sucks?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users