0

Hi! I'm new here! I have a quick question about an error I found in my script.

I'll jump straight into the code and then make my question:

$description = $_POST['desc'];

this is a text description for example "Monthly Tuition".

$amount = $_POST['amount'];

price of tuition

$dlnumber = $_POST['cedula'];

drivers license number of the person paying tuition.

foreach($cedula as $key => $cedula) {  $description = $description[$key]; echo $description;       }

When I run the array $description[$key] through a variable as shown above, the array is echoed properly only on the first loop through. After the first time around, it just spits out the letter "e" instead of the correct variable. However, if I run the following,

foreach($cedula as $key => $cedula) {  echo $description[$key];  }

, without first assigning the description to a variable, it runs perfectly!

So, I can obviously see that the loop is doing something funky with the variable. Any ideas why?

Hope I've explained this matter clearly! Thanks for any ideas!

~Shayna

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by diafol
0

Try to avoid overwriting variables still in use:

foreach($cedulas as $key => $cedula) { 
 echo $description[$key]; 
}

If you make $description = $description[$key], $description is now a single value, not an array. So $description[$key] ceased to exist after that point onwards.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.