AdamFerguson Posted March 6, 2014 Share Posted March 6, 2014 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 Quote Link to comment Share on other sites More sharing options...
PravinS Posted March 6, 2014 Share Posted March 6, 2014 (edited) can you show us the actual code Edited March 6, 2014 by PravinS Quote Link to comment Share on other sites More sharing options...
AdamFerguson Posted March 6, 2014 Author Share Posted March 6, 2014 Hi, The code: $key1 = $shipping['orderid'][0]; $key2 = $dbitem['ProductCode']; // store the shipping details for the order $this->cpc[$key1][$key2]['shiptype'] = $shipping['shiptype'][0]; $this->cpc[$key1][$key2]['marketplace'] = $shipping['marketplace'][0]; $this->cpc[$key1][$key2]['ship_name'] = $shipping['ship_name'][0]; $this->cpc[$key1][$key2]['ship_address1'] = $shipping['ship_address1'][0]; $this->cpc[$key1][$key2]['ship_address2'] = $shipping['ship_address2'][0]; $this->cpc[$key1][$key2]['ship_city'] = $shipping['ship_city'][0]; $this->cpc[$key1][$key2]['ship_state'] = $shipping['ship_state'][0]; $this->cpc[$key1][$key2]['ship_postcode'] = $shipping['ship_postcode'][0]; $this->cpc[$key1][$key2]['ship_countrycode'] = $shipping['ship_countrycode'][0]; $this->cpc[$key1][$key2]['ship_phone'] = $shipping['ship_phone'][0]; if you print any of these individually (except any that being with $this->cpc) the value is printed to the screen so I know that everything has a value. Why then, would $this->cpc array not hold any of these values? $key1, $key2, all the $shipping variables all have values when printed. But none are assigned to the $this->cpc array. Quote Link to comment Share on other sites More sharing options...
Solution AdamFerguson Posted March 6, 2014 Author Solution Share Posted March 6, 2014 Hi, I figured it out, the array was treating $key1 and $key2 as integers and therefore $key1 (which was 202-7465746-2875675) was not being treated as a string as I had hoped. Just wrapped them like this in double quotes: $this->cpc["{$key1}"]["{$key2}"]['ship_phone'] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.