Forum Moderators: coopster
Warning: isset() only works with variables as passing anything else will result in a parse error. For checking if constants are set use the defined() function.
I can't find a similar function that tests for the existence of an array or any other way to do it, but I'm sure there's an easy way... anybody? :(
$array = array();
if (isset($array)) {
print 'true'; // prints this one.
} else {
print 'false';
}
$array = array();
if ($array) {
print 'true';
} else {
print 'false'; // prints this one.
}
$array = array();
Also, when I use isset(); for my test, and the array exists, the script works fine. When the array doesn't exist, I get the following message (edited for simplicity):
Notice: Undefined variable: array in myFile
Notice: Undefined variable: array in pathToMyFile
Here are the exact tests mentioned so far that I've used, among others:
if (!isset($accessories)) {
if (!is_array($accessories)) {
My array is named $accessories in this case, if it is actually created.
Really the only problem I seem to have at this point is having the Notices show up in my page. Everything seems to work otherwise. Is there perhaps another way to eliminate the notices?
Using isset() should not throw a notice error. You must be doing something else in your control logic test. What is the exact statement that is throwing the error?