Arrays

Hi,

Can someone please help. I have an array such as:

$this->cpc[$key1][$key2][‘shiptype’] = $value;

But when I try to print the value the array is empty:

echo $this->cpc[$key1][$key2][‘shiptype’];

But, if I don’t use variable names such as $key1 and $key2 and instead use the values of $key1 and $key2, it works. Such as: (these two lines do set the value in the array and will print it to the screen)

$this->cpc[202-3454-234234][9685766][‘shiptype’] = $value;
echo $this->cpc[202-3454-234234][9685766][‘shiptype’];

The $key1 and $key2 DEFINITELY hold the correct values so what is going on here please? Does anyone know?

Best Regards, Adam

how are you accessing $key1 and $key2?

It would be helpful f you posted all the code.

Have you tried altering the ’ and " and resubmitting? What error pops out when you run it now? In my experience I can sometimes change the ’ or " around the variables after the echo and it will work. Let me know. Thanks.

if $key1 and $key2 are strings, I believe you need to hage quotes (’) around them…

Sponsor our Newsletter | Privacy Policy | Terms of Service