-7

Given this PHP array:

$options['systems'] = array(1, 2, 3)

How would I append the value 4 to the $systems array within the $options array?

Garry Pettet
  • 7,482
  • 22
  • 60
  • 97

2 Answers2

1

You could use array_push to push additional items like so:

array_push($options['systems'], 4);

Or the shorthand version:

$options['systems'][] = 4;
  • Please don't post answers on obviously off-topic questions! [See: **Should one advise on off topic questions?**](http://meta.stackoverflow.com/q/276572/1768232) Off-topic questions can be closed and deleted, which could nullify your contribution. – John Conde Mar 10 '17 at 15:28
0

You can use php array_push function. Like this. array_push($options['systems'],4);

you can read the detail of array_push from below link.array_push manual

  • Please don't post answers on obviously off-topic questions! [See: **Should one advise on off topic questions?**](http://meta.stackoverflow.com/q/276572/1768232) Off-topic questions can be closed and deleted, which could nullify your contribution. – John Conde Mar 10 '17 at 15:28