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 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. 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 Link to comment https://forums.phpfreaks.com/topic/281518-array-problem/#findComment-1446555 Share on other sites More sharing options...
.josh Posted August 24, 2013 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/>"; } 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! Link to comment https://forums.phpfreaks.com/topic/281518-array-problem/#findComment-1446560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.