-2

I have this array:

Array
(
    [0] => Array
        (
            [char_id] => 205
        )

    [1] => Array
        (
            [char_id] => 954
        )
)

And this array:

Array
(
    [0] => Array
        (
            [england] => 523
        )

    [1] => Array
        (
            [poland] => 9546
        )
)

How I can combine this arrays for inserting in database? I use codeigniter! I want this result:

$data =  Array
        (
            Array
                (
                    [char_id] => 205
                    [england] => 523
                )
        
            Array
                (
                    [char_id] => 954
                    [poland] => 9546
                )
        )

I want to use function insert_batch $this->db->insert_batch('mytable', $data);

Number of elements from arrays is different but same count every time!

1
  • Actually it's quite simple. You need to understand how to use array tags for example var_dump($data1[0][0]); and using a foreach loop to build new array. Commented Dec 30, 2021 at 1:46

1 Answer 1

-1
$arrayA = array();
$arrayA[] = array("char_id"=>205);
$arrayA[] = array("char_id"=>954);

$arrayB = array();
$arrayB[] = array("england"=>523);
$arrayB[] = array("poland"=>9546);

$arrayC = array();
foreach($arrayA as $key=>$a){
    $arrayC[$key] = array_merge($arrayA[$key],$arrayB[$key]);
}

print_r($arrayC);
Sign up to request clarification or add additional context in comments.

1 Comment

Please close duplicate questions instead of answering them. When duplicate questions are answered, the Roomba cannot do its important work. When you do answer, always explain your solution.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.