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

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.