Skip to main content
edited tags; edited title; edited tags
Link
200_success
  • 145.7k
  • 22
  • 191
  • 481

Simplifying loops Splitting three comma-delimited strings

Possibly no good title for this
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

How would I re-code this PHP code please Simplifying loops

so I've been reading about loops this morning, to try to improve this snippet of code:

$deliveryoutcode1 = array(); $deliveryoutcode1 = explode(",",$rows['deliveryoutcode1']); $deliveryoutcode2 = array(); $deliveryoutcode2 = explode(",",$rows['deliveryoutcode2']); $deliveryoutcode3 = array(); $deliveryoutcode3 = explode(",",$rows['deliveryoutcode3']); 

I started to read about loops this morning and I came up with this:

$i=1; while ($i <= 3) { // Output values from 0 to 3 $deliveryoutcode[$i] = array(); $deliveryoutcode[$i] = explode(",",$rows['deliveryoutcode' . $i . '']); $i++; } 

thisThis works great, but I'm wondering if there is a better way to do this?. It appears as though I've come up with the best way but as this is my first attempt at loops, I better ask the experts. Thanks

How would I re-code this PHP code please

so I've been reading about loops this morning, to try to improve this snippet of code:

$deliveryoutcode1 = array(); $deliveryoutcode1 = explode(",",$rows['deliveryoutcode1']); $deliveryoutcode2 = array(); $deliveryoutcode2 = explode(",",$rows['deliveryoutcode2']); $deliveryoutcode3 = array(); $deliveryoutcode3 = explode(",",$rows['deliveryoutcode3']); 

I started to read about loops this morning and I came up with this:

$i=1; while ($i <= 3) { // Output values from 0 to 3 $deliveryoutcode[$i] = array(); $deliveryoutcode[$i] = explode(",",$rows['deliveryoutcode' . $i . '']); $i++; } 

this works great, but I'm wondering if there is a better way to do this? It appears as though I've come up with the best way but as this is my first attempt at loops, I better ask the experts. Thanks

Simplifying loops

I've been reading about loops this morning, to try to improve this snippet of code:

$deliveryoutcode1 = array(); $deliveryoutcode1 = explode(",",$rows['deliveryoutcode1']); $deliveryoutcode2 = array(); $deliveryoutcode2 = explode(",",$rows['deliveryoutcode2']); $deliveryoutcode3 = array(); $deliveryoutcode3 = explode(",",$rows['deliveryoutcode3']); 

I started to read about loops this morning and I came up with this:

$i=1; while ($i <= 3) { // Output values from 0 to 3 $deliveryoutcode[$i] = array(); $deliveryoutcode[$i] = explode(",",$rows['deliveryoutcode' . $i . '']); $i++; } 

This works great, but I'm wondering if there is a better way to do this. It appears as though I've come up with the best way but as this is my first attempt at loops, I better ask the experts.

Source Link

How would I re-code this PHP code please

so I've been reading about loops this morning, to try to improve this snippet of code:

$deliveryoutcode1 = array(); $deliveryoutcode1 = explode(",",$rows['deliveryoutcode1']); $deliveryoutcode2 = array(); $deliveryoutcode2 = explode(",",$rows['deliveryoutcode2']); $deliveryoutcode3 = array(); $deliveryoutcode3 = explode(",",$rows['deliveryoutcode3']); 

I started to read about loops this morning and I came up with this:

$i=1; while ($i <= 3) { // Output values from 0 to 3 $deliveryoutcode[$i] = array(); $deliveryoutcode[$i] = explode(",",$rows['deliveryoutcode' . $i . '']); $i++; } 

this works great, but I'm wondering if there is a better way to do this? It appears as though I've come up with the best way but as this is my first attempt at loops, I better ask the experts. Thanks