fmosse Posted August 24, 2013 Share Posted August 24, 2013 I have a strange problem... I have oscommerce installed and I must modify an array that has 3 values. If I write this code: print_r(array_values($shipping)); print"<hr>"; print_r(array_values($shipping)); print"<hr>"; echo "start<br>"; $elementos_de_array=count($shipping); echo "($elementos_de_array)<br>"; $desdecero=0; while ($desdecero<$elementos_de_array) { echo "$desdecero:".$shipping['$desdecero']."<br>"; $desdecero++; } echo "end<br>"; I receive this in the web: Array ( [0] => shippingpersonalizadodos_shippingpersonalizadodos [1] => Envio a domicilio (Envio a domicilio) [2] => 55 ) start(3)0:1:2:end so... How do I get the values??? Thanks, Francisco Quote Link to comment https://forums.phpfreaks.com/topic/281518-array-problem/ Share on other sites More sharing options...
.josh Posted August 24, 2013 Share Posted August 24, 2013 $shipping['$desdecero'] should be $shipping[$desdecero] variables will be parsed inside double quotes, but not single quotes. But you shouldn't really put it in quotes to begin with, as it is less efficient. Quote Link to comment https://forums.phpfreaks.com/topic/281518-array-problem/#findComment-1446552 Share on other sites More sharing options...
fmosse Posted August 24, 2013 Author Share Posted August 24, 2013 $shipping['$desdecero'] should be $shipping[$desdecero] variables will be parsed inside double quotes, but not single quotes. But you shouldn't really put it in quotes to begin with, as it is less efficient. I have tried and I still see the same: print_r(array_values($shipping)); print"<hr>"; echo "start<br>"; $elementos_de_array=count($shipping); echo "($elementos_de_array)<br>"; $desdecero=0; while ($desdecero<$elementos_de_array) { echo "$desdecero:".$shipping[$desdecero]."<br>"; $desdecero++; } echo "end<br>"; Array ( [0] => shippingpersonalizadodos_shippingpersonalizadodos [1] => Envio a domicilio (Envio a domicilio) [2] => 55 ) start (3) 0: 1: 2: end Quote Link to comment https://forums.phpfreaks.com/topic/281518-array-problem/#findComment-1446555 Share on other sites More sharing options...
Solution .josh Posted August 24, 2013 Solution Share Posted August 24, 2013 okay, then $shipping is probably an associative array (named keys), not numeric (numbered keys). do this: print_r($shipping); What do you get? If it's an associative array then you will need to use foreach to loop through the array. foreach ($shipping as $key => $value) { echo $value. "<br/>"; } Quote Link to comment https://forums.phpfreaks.com/topic/281518-array-problem/#findComment-1446557 Share on other sites More sharing options...
fmosse Posted August 24, 2013 Author Share Posted August 24, 2013 okay, then $shipping is probably an associative array (named keys), not numeric (numbered keys). do this: print_r($shipping); What do you get? If it's an associative array then you will need to use foreach to loop through the array. foreach ($shipping as $key => $value) { echo $value. "<br/>"; } Thanks for your help!! I used that method and I could access then each value and modify them! Quote Link to comment https://forums.phpfreaks.com/topic/281518-array-problem/#findComment-1446560 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.