1

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

@ odaddict, no need to third paramter ($index).
the element need to be insert always 4
@python: You can just delete that parameter (see my updated post) or make it a default argument with default value of 4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.