0

I've got 6 arrays - 1 with name and 5 with some properties - which should be assigned to that name. All values are of course in order. I'd like to make a 2-dimensional array with will be later put into CSV and the result should be as on the table here:

Table on TinyPic

I guess that i have to do 2 loops here, but I can't make them work. How to construct such array?

Solution found

I've connected all arrays:

$final_array = array($nazwa_array,$new_ilosc_array,$new_koszt_array,$new_cena_lifo_array,$new_cena_fifo_array,$new_rodzaj_array);

I've found a matrix transposition function, which returns array in correct order:

function transpose($array) {
    array_unshift($array, null);
    return call_user_func_array('array_map', $array);

}

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
chilliq
  • 1,212
  • 3
  • 13
  • 32

1 Answers1

1
$a = array();
foreach ( $names AS $key => $value ) {
    $a[$key]['name'] = $value;
    $a[$key]['property1'] = $value.'->'.$property1_array[$key];
    $a[$key]['property2'] = $value.'->'.$property2_array[$key];
    $a[$key]['property3'] = $value.'->'.$property3_array[$key];
    $a[$key]['property4'] = $value.'->'.$property4_array[$key];
    $a[$key]['property5'] = $value.'->'.$property5_array[$key];
}
blue
  • 1,939
  • 1
  • 11
  • 8