Reputation: 881
I am trying to added the following info to my array: inserted_by_user_id -> 5
If I do a print_r on $array_post I get data like this:
Array ( [saw_by_id] => 18 [appt_status_id] => 2 [reason_id] => 1 [pre_notes] => [howheard_id] => [marketing_event_id] => [start] => 2016-05-09T08:20:00+00:00 [end] => 2016-05-09T08:30:00+00:00 [allDay] => 0 [location_id] => 1 [contact_id] => 3102 [company_id] => 1 )
I'm trying to add the info like this:
// array_map should walk through $array - replaces blank values that are serialized from the form and makes them null
$array_post = array_map(function($value) {
return !strlen($value) ? NULL : $value;
}, $_POST);
$array_post.push({inserted_by_user_id: '5'});
I am using array_map on the array also to remove blanks before inserting into my DB.
When I try to use this push I get this error:
Parse error: syntax error, unexpected '{' in THIS FILE on line 20
Line 20 is the line with .push on it.
If I don't use .push, everything works fine. I just want to add that info to each array that's passed to this page.
Upvotes: 0
Views: 1024
Reputation: 589
in php you use. I just did an edit to try to make it a php question, as this is what language you are using
$array_post['inserted_by_user_id'] = '5';
Upvotes: 1
Reputation: 551
You can simple use array_merge function and insert data into table -
$array_post = array_merge($array_post, array('inserted_by_user_id'=> '5'));
Upvotes: 2