krishna krishna -4 years ago 71
PHP Question

How to combine arrays in add more functionality in codigniter to form into single array

I am having add more functionality in codeigniter Here it is http://jsfiddle.net/touqeershafi/t7t6gzve/. Here i am array like this

[faculty] => Array
(
[0] => 2
[1] => 3
[2] => 4
)
[message] => Array
(
[0] => 'test1'
[1] => 'test2'
[2] => 'test3'
)

and also i having an last inserted id from another db $last_inserted_id=1;
Here i want to combine like this, to form an array

$array =
array(
'faculty' => 2 ,
'message' => 'test1',
$id => 1
),
array(
'faculty' => 3 ,
'message' => 'test2',
$id => 1
),
array(
'faculty' => 4,
'message' => 'test3',
$id => 1
).

Thanks for everyone for your suggestions and time.

Answer Source

I hope this will you:

$array = [];
$faculty = array(2, 3, 4);
$message = array('test1', 'test2', 'test3');
$id = 1;
for ($key = 0; $key < count($faculty); $key++) {
    $array[$key]['faculty'] = $faculty[$key];
    $array[$key]['message'] = $message[$key];
    $array[$key]['id'] = $id;
}
print_r($array);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download