Question

I experience something strange with an undefined index..

$vatcode = 'U25';
echo $this->vatcode_ids['U25']."\n";
echo $this->vatcode_ids[$vatcode]."\n";

foreach($this->vatcode_account_ids as $id => $vatcode){
    echo $vatcode."\n";
    echo $this->vatcode_ids[$vatcode]; // undefined index
}

this returns:

681
681
U25  

Notice: Undefined index: U25   in /var/www/.....php on line 64

I don't get it?!

Was it helpful?

Solution

From empty line printed before Notice massage i assume your $vatcode variable contains some ending new line character. If so it does not match any key in $this->vatcode_ids array.

You should use some trimming function as Dan Lee suggested in comments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top