How to merge multiple arrays in codeigniter?

by lindsey.homenick , in category: PHP Frameworks , 7 months ago

How to merge multiple arrays in codeigniter?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by wilmer.lemke , 7 months ago

@lindsey.homenick 

In CodeIgniter, you can merge multiple arrays using the array_merge() function. Here's an example of how you can merge multiple arrays in CodeIgniter:

1
2
3
4
5
6
7
$array1 = array('a', 'b', 'c');
$array2 = array('d', 'e', 'f');
$array3 = array('g', 'h', 'i');

$merged_array = array_merge($array1, $array2, $array3);

print_r($merged_array);


This will output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Array
(
    [0] => a
    [1] => b
    [2] => c
    [3] => d
    [4] => e
    [5] => f
    [6] => g
    [7] => h
    [8] => i
)


You can also use the "+" operator to merge arrays in CodeIgniter:

1
2
3
$merged_array = $array1 + $array2 + $array3;

print_r($merged_array);


Both methods will merge the arrays together into a single array.