1

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

2
  • Because $_SESSION['filtros_web_jobs'] might have other values that I am not putting here so the code remains clean. Commented Sep 10, 2013 at 15:34
  • correct usage of array_merge would help $x=array_merge($y, $z); php.net/manual/en/function.array-merge.php Commented Sep 10, 2013 at 15:34

4 Answers 4

4

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'] );
Sign up to request clarification or add additional context in comments.

Comments

2

From Array merge on PHP.net

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);

Comments

1

array_merge returns the new, merged array. Try:

$a = array_merge( $_SESSION['filtros_web_jobs'], $_POST['filtros_web_form'] );
var_dump($a);

Comments

0

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'] );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.