2

I have a $_POST array and I would like to add a key at the very end.

So what I am doing is,

array_push($_POST['ques_15'] , '');

it works but I am getting a warning

Warning: array_push() expects parameter 1 to be array, null given 

How can I remove this warning without turning off display errors.

2
  • 1
    $_POST['ques_15'] = ''; Commented Aug 1, 2014 at 11:39
  • just $_post don't give index . Then it will consider it as a string. Commented Aug 1, 2014 at 11:39

5 Answers 5

5

I think you simply want to do:

$_POST['ques_15'] = '';

It will add at the end of $_POST array value '' with key ques_15

Sign up to request clarification or add additional context in comments.

Comments

4

$_POST is an associative array.

Both array_push() and the directly providing key:value to your array will work.

Instead of array_push() , I would go like this :

<?php

$_POST['ques_15'] = '';

?>

Comments

3

It's simple as:

$_POST[] = 'value';

or

$_POST['yourkey'] = 'value'

Comments

1

it will be array_push($_POST , ''); as $_POST['key'] is not an array. $_POST is an array.

Comments

0

As @billyonecan mentioned in comment simply using $_POST['ques_15'] = '' can solve your problem ..:)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.