Array_diff_key return value

software development

#1

OK >> Figured it out. I’m leaving this up here, hopefully it will help someone else. As I suspected, it was stupid. I didn’t do sizeof() on the $req_keys_exist array and I needed to unset $compare_keys before each time it processed.

This seems to happen to me a lot…I ask for help and BOOM the little light goes on in my head and I figure it out. Now if only this had happened about 3 hours ago…

I’m doing something wrong and it’s probably stupid, but for the life of me I can’t figure it out. Here’s the deal…I set some required values in a session array ($_SESSION[“req_form_vars”]) and I want to check that array against values passed via $_POST to ensure they have the same values. I took the posted vars and put them into an array to make the values (if they exist) look just like the session array.

Then I was going to use array_diff_key to see if values were returned that didn’t match. If they don’t match, then I set a flag that does other stuff.

SESSION array ( [req_form_vars] => Array ( [opt::Color] => opt::Color [opt::Size] => opt::Size ) )

POST vars = Array ( [opt::Color] => opt::Color [opt::Size] => opt::Size )

req_key_exists = Array ( ) // print_r not returning a value here.

Code:
$req_keys_exist = array_diff_key($_SESSION[“req_form_vars”], $compare_keys);

if($req_keys_exist > 0) { // tried empty() too.
$req_options = “n”;
}
else {
$req_options = “y”;
}

Here’s what the PHP.net manual says about array_diff_key:
array_diff_key() returns an array containing all the values of array1 that have keys that are not present in any of the other arguments. Note that the associativity is preserved. This function is like array_diff() except the comparison is done on the keys instead of the values.

Help with this would be appreciated!
Angela

================================
Angela Gann
CrimsonDryad Web Design Services
Web Design, Custom Software Development
http://www.crimsondryad.com