0

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.

2
  • 1
    array_map looks like PHP. .push looks like JavaScript. It seems that you're mixing up programming languages. Commented May 12, 2016 at 2:40
  • Oh my. You are correct. I had a moment here. Forgive me. I'll try to figure it out now! Commented May 12, 2016 at 2:43

2 Answers 2

2

You can simple use array_merge function and insert data into table -

$array_post = array_merge($array_post, array('inserted_by_user_id'=> '5'));
Sign up to request clarification or add additional context in comments.

1 Comment

php 5.4 and > use ['inserted_by_user_id'=> '5'] instead of array()
1

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

1 Comment

Thank you very much everyone for the prompt help. Thanks for changing this to a php related question, and sorry about that again. I got it working with the above options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.