I have the following method where you pass a list of items in, and the first item is what you want to see if it exists, and the following items are the path to the item.
In the following I have 2 print_r statements, one before the for and one after it.
public function exists(){
$keys = func_get_args();
$value = array_shift($keys);
$ref = &$_SESSION;
print_r($_SESSION);
for($x = 0; $x < sizeof($keys); $x++){
$ref = &$ref[$keys[$x]];
}
print_r($_SESSION);
if(!is_array($ref)){
unset($ref);
return false;
}
$found = in_array($value, $ref);
unset($ref);
return $found;
}
and when I call it like this:
$obj->exists(123, "cart");
I get these two arrays from those print_r's:
Array
(
[id] => 1
[email] => [email protected]
[user] => TheColorRed
[first] => Billy
[last] => Bob
[ZingLoggedIn] => 1
)
Array
(
[id] => 1
[email] => [email protected]
[user] => TheColorRed
[first] => Billy
[last] => Bob
[ZingLoggedIn] => 1
[cart] =>
)
My question is, why is it adding cart to the array? It should only be checking to see if it exists.
E_ALLerror reporting level and check your logs first. PS: yourunsetis completely redundant there.error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICTanddisplay_errors = On