简体   繁体   中英

Push key, value to array: jQuery

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.

您可以简单地使用array_merge函数并将数据插入表中-

$array_post = array_merge($array_post, array('inserted_by_user_id'=> '5'));

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';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM