How do I append a value to an array within an array in PHP?

Garry Pettet

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?

user5066478

You could use array_push to push additional items like so:

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

Or the shorthand version:

$options['systems'][] = 4;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I append a string to an array of strings within a loop in C?

How do I get a value within a class stored within an array?

How do I access an array within an array?

How do i access an array within an array

How do I parse Array within Array

How do I find the maximum value in an array within a dataframe column?

PHP - How do I modify variables within an array?

PHP - How do I expand all arrays within an array

How do I properly construct an array within a class in PHP?

How do I append to array as an extension in swift

How do I append an item to an array in a pipeline?

How do I append to a section of an array? [[]]

In Java, how do I most efficiently find an array within a JSON array based on the value of an element of the subarray?

How do I link within an object/array?

Append value to multidimensional array PHP

PHP: append string value to array

How do I retrieve an array value created in a PHP function?

PHP - How do I unset an array index by value inside that index

How do I access a php array value containing a forward slash

(PHP) How do i refer a specific array value in a checkbox?

PHP - How do I get a specific value of a multidimensional array

How do I convert an array into an object within array - Angular and Javascript

How do I check if there's an array within an array

Using PHP and Laravel, why can i not append a variable to a value in an array?

How do I update an array within an object from within state?

How do I append date interval (date span) results into an PHP array?

How can I filter for entries that do NOT contain a key-value pair within a nested array

How Do I Print Correct Random Array Value Within If/Else Statement in my Text Adventure?

Node.js - How do I retrieve the value of an element within an object/array