开发者

How to map array to element of other corespodning array?

开发者 https://www.devze.com 2023-01-31 21:48 出处:网络
I Have an array A $A = Array ( [0] => Array ( [0] => A0;B0;C0;E0;;626.00; [1] => A1;B1;C1;E1;;6212.00;

I Have an array A

$A = Array
(
    [0] => Array
    (
        [0] => A0;B0;C0;E0;;626.00;
        [1] => A1;B1;C1;E1;;6212.00;
        [2] => A2;B2;C3;E2;;226.00;
        [3] => A3;B3;C3;E3;;632.00;
    )


)

$B = Array
(
    [0] =>开发者_如何学编程; Array
    (
        [0] => REP00
        [1] => 
        [2] => REP02
        [3] => 
    )
)

I am going to write the

function map_array_element($A,$B){
    $C = array();
    foreach($A as $key=>$value){
        foreach($value as $k=>$v){
            $empty_case = str_replace(';;', '; ', $v);
                $row = explode(';', $replace);
              /*the idea to got the array of 
            $row=array(
                    0=>A,
                    1=>B,
                    2=>C,
                    3=>E,
                                4=>   //this element will map to corresponding $B           )
            */
          //TODO


    }
  }
return $C;
}

Tthis function will return an new array like this that will

   $C = Array
(
    [0] => Array
    (
        [0] => A0;B0;C0;E0;REP00;626.00;
        [1] => A1;B1;C1;E1;;6212.00;
        [2] => A2;B2;C3;E2;REP02;226.00;
        [3] => A3;B3;C3;E3;;632.00;
    )


)

Who know to do this manipulate?

thanks


You are almost there. You need to take care of the right index of array C.

function map_array_element($A,$B){
        $C = array();
        foreach($A as $key=>$value){
                foreach($value as $k=>$v){
                        $row = explode(';', $v);
                        $row[4] = $B[$key][$k];

                        $C[$key][$k] = implode(';',$row);    
                }
        }
        return $C;
}

See it

0

精彩评论

暂无评论...
验证码 换一张
取 消