Tutorials
Looping through variables using concatenation with PHP
Written by Andy Sharman Saturday, 25 July 2009 14:22
Recently a friend was given the task of ordering a group of variables that would be similiar to this:
| Group of ordered PHP variables | |
1 |
$var1 = 10; |
As you can see these items are not in array, and although it would be a best practice to have the group in array these are unchangeable, possibly an output from an existing system. What does need to be done is place them into an array using concatenation and a simple loop. Below is the loop to do such:
1 |
//Denotes that the group of vars starts at 1 i.e. $var1 |
This will output a nice array of items, which you can now use and manipulate a lot easier than the original group of variables.
All content is copyrighted to udjamaflip.com 2009-2010, All rights reserved.