Array_merge returns an array. It does not mutate the arrays that are passed to it.
$merged = array_merge( $_SESSION['filtros_web_jobs'], $_POST['filtros_web_form'] );
Question
This code doesn't seem to work:
session_start();
$_SESSION['filtros_web_jobs'] = array();
array_merge( $_SESSION['filtros_web_jobs'], $_POST['filtros_web_form'] );
var_dump($_SESSION);
var_dump($_POST);
session_write_close();
exit;
Outputs:
array(1) {
["filtros_web_jobs"]=>
array(0) {
}
}
array(1) {
["filtros_web_form"]=>
array(1) {
["cola"]=>
string(18) "fisica_Renova_zxcv"
}
}
Any clue?
Thanks
Solution
Array_merge returns an array. It does not mutate the arrays that are passed to it.
$merged = array_merge( $_SESSION['filtros_web_jobs'], $_POST['filtros_web_form'] );
OTHER TIPS
Return Values
Returns the resulting array.
You aren't setting the output to anything - Try this:
$output = array_merge( $_SESSION['filtros_web_jobs'], $_POST['filtros_web_form'] );
print_r($output);
array_merge returns the new, merged array. Try:
$a = array_merge( $_SESSION['filtros_web_jobs'], $_POST['filtros_web_form'] );
var_dump($a);
You have not cached the data that array_merge function is giving you after merging the arrays.
$mergedArray = array_merge( $_SESSION['filtros_web_jobs'], $_POST['filtros_web_form'] );