Jump to content

Array + Undefined Variables


noobified

Recommended Posts

im wondering if someone could have a look at this and point out what is wrong, it keeps giving the following notice

 

PHP Notice:  Undefined variable: themeName0
PHP Notice:  Undefined variable: blockArrowColorTheme0
PHP Notice:  Undefined variable: blockBackgroundImageTheme0 

 

case "themeImageSubmit":
for ($x = 0; $x <= $totalThemes; $x++) {
	$themeImageValues["themeName"][$x] = ${"themeName$x"};
	$themeImageValues["${"themeName$x"}"]["blockArrowColor"] = ${"blockArrowColorTheme$x"};
	$themeImageValues["${"themeName$x"}"]["blockBackgroundImage"] = ${"blockBackgroundImageTheme$x"};
}
themeImageSubmit($themeImageValues, $totalThemes);
break;

Link to comment
https://forums.phpfreaks.com/topic/121978-array-undefined-variables/
Share on other sites

Does this help?

 

<?php
for($i=0; $i<8; ++$i)
{
    echo $i,"\t";
    switch($i)
    {
    case 1: echo "One"; break;
    case 2:
    default: echo "Thingy"; break;
    case 3:
    case 4: echo "Three or Four"; break;
    case 5: echo "Five"; break;
    }
    echo "\n";
}
?>

I would turn notice's off in your php.ini file frankly. Basically it wants you to declare a variable before you try to use it.. so for instance.. instead of dynamically creating

 

$themeImageValues["themeName0"]["blockArrowColor"]

 

it wants you to do something like this:

 

$themeImageValues["themeName0"] = array ("blockArrowColor", "blockBackgroundImage");

 

and THEN assign values to to them. Since this is just not practical in PHP, I would simply turn notices off, most people do.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.