I have associative array which looks like this.
$arr = array(
"FIRST" => 1,
"SECOND => 2,
"FOURTH => 4
);
The idea is how to “add” data to this array depending of expression.
Here is what I’m trying to do:
if(3 == 3) {
$str = array("THIRD" => 3);
}
$arr = array(
"FIRST" => 1,
"SECOND => 2,
$str,
"FOURTH => 4
);
The problem is that the code above add $str as an array in $arr, not like “THIRD” => 3
What about http://php.net/manual/en/function.array-merge.php
Then you can merge the two arrays:
But you can also do it on another way: