Jump to content

array problem


fmosse
Go to solution Solved by .josh,

Recommended Posts

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
Share on other sites

$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: :shrug:

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
Share on other sites

  • Solution

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
Share on other sites

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.