0

I have 3 arrays:

$firstArray =  Array([0] => 33 [1] => 34)
$secongArray = Array([0] => 71300 [1] => 72300)
$thirdArray =  Array([0] => 71300 [1] => 72300 [2] => 234234)

How do I make it something like this,

$outputArray = array
   (
   array(33,71300,71300),
   array(34,72300,72300),
   array(NULL,NULL,234234),
   //.....
   );
mickmackusa
  • 43,625
  • 12
  • 83
  • 136
srinisunka
  • 1,159
  • 2
  • 7
  • 10
  • 1
    Are you trying to make those three arrays into a single 2-dimesional array, and then transpose it? – Mark Baker Dec 24 '14 at 17:03
  • 1
    Yes, @MarkBaker I actually have (33,34) (71300,72300) and (71300,72300, 234234) as variables then I used explode to convert them into arrays. And now I have these arrays and need to convert them into a 2 dimensional – srinisunka Dec 24 '14 at 17:09

2 Answers2

2
$max = max(count($firstArray),count($secongArray),count($thirdArray));
$outputArray = array();
for($i==0;$i<$max;$i++) {
    //test unset values
    if(!isset($firstArray[$i])) $firstArray[$i] = null;
    if(!isset($secongArray[$i])) $secongArray[$i] = null;
    if(!isset($thirdArray[$i])) $thirdArray[$i] = null;

    $outputArray[] = array($firstArray[$i],$secongArray[$i],$thirdArray[$i]);
}
Mohammad Alabed
  • 809
  • 6
  • 17
Jasmin Mistry
  • 1,459
  • 1
  • 18
  • 23
1
$firstArray =  array(33, 34);
$secondArray = array(71300, 72300);
$thirdArray =  array(71300, 72300, 234234);

$outputArray = call_user_func_array(
    'array_map',
    array_merge(
        array(NULL),
        array(
            $firstArray,
            $secondArray,
            $thirdArray
        )
    )
);
var_dump($outputArray);
Mark Baker
  • 209,507
  • 32
  • 346
  • 385