php dynamic value array variable code example
Example 1: add values to array dynamically php
There are quite a few ways to work with dynamic arrays in PHP. Initialise an array:
$array = array();
Add to an array:
$array[] = "item";
$array[$key] = "item";
array_push($array, "item", "another item");
Remove from an array:
$item = array_pop($array);
$item = array_shift($array);
unset($array[$key]);
There are plenty more ways, these are just some examples.
Example 2: adding data dynamically to empty array in php
$array[] = "item";
$array[$key] = "item";
array_push($array, "item", "another item");