Once upon a time, in a land far, far away, was a town called "$languages
." In this town lived many little "$language
"s - some big, some small, some well-fed, some skinny... it was the variety of the "$language
"s that made the town so great.
Once a year, the little "$language
"s would, one by one, sojourn to a strange and marvelous place. In this strange place, every language became equally minuscule, and a strange thing - some called it a "$qfactor
," (but no one knew why) came out of them. For some, it was altogether missing, and they became one. Sometimes, it was malformed - in which case the "$language
" would be promptly sent running home.
Then, every last little "$language
" would walk through a magical gateway (called The Great if
). This gateway that caused great consternation to those "$language
"s who passed through it, as it would determine whether or not they were one of the "$accepted
". These "$accepted
" would be magically whisked away, to a place no-one knew and no-one dared to (or could?) speak of - for, strangely, the next day, every "$language
," would be found returned to his home.
Then, one day, the if
became broken, and each and every "$language
" would be quite rudely spit out as a foreign voice declared: Notice: Undefined variable: langauge in /var/www/nginx-default/path/to/lib/http/languages.php
.
TL:DR;
foreach ($raw_languages as $language_value) {
$language = '';
$language_values = explode(';', $language_value);
// If the qfactor was not supplied
if (count($language_values) == 1) {
// Lower-case the language
$language = strtolower($language_values[0]);
// Default to a q-factor of one
$qfactor = 1;
// If the qfactor was supplied
} else {
$language = strtolower($language_values[0]);
$qfactor = $language_values[1];
// Validate the q-factor
if (!is_numeric($qfactor)) {
// If it's not numeric (invalid) skip it
continue;
}
}
// If this isn't one of the accepted languages, skip it.
if (!in_array($langauge, $accepted)) {
continue;
}
// Add it to the languages array
$languages[$language] = $qfactor;
}
For some reason, upon if (!in_array($language, $accepted)
, I get an error stating: `Notice: Undefined variable: langauge in /var/www/nginx-default/path/to/lib/http/languages.php
. The strange thing is that I can even sneak in a call to print()
on the same line (by putting it in the if
statement) and I will not get the same error - in fact, doing so gives the expected output!
I am greatly confused as to why this could be happening (and rather bored because of the work it's blocking, as you can see by the story), so any help would be appreciated.
Thanks!
You spelt language
wrong:
if (!in_array($langauge, $accepted)) {
continue;
}
Swap the a
and u
in $langauge
:)
Notice: Undefined variable: langauge in /var/www/nginx-default/path/to/lib/http/languages.php
If you copy-pasted error text, so you misspelled variables name.