Hello, could I assign a value for each character in a string?
For example: "url.php?var=19200"
1, 9, 2, 0, 0
$char1 = 1, $char2 = 9, $char3 = 2, $char4 = 0, $char5 = 0
Same for any value.
I have no clue how to do this.
Help with a smart function.
Moderator: General Moderators
Help with a smart function.
Last edited by lovelf on Wed Jan 14, 2009 5:24 am, edited 2 times in total.
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Help with a smart function.
strlen will give you how long the string is.
To split it up, you could use a for loop with this number and go through the original string character at a time and save them in variables you want.
To split it up, you could use a for loop with this number and go through the original string character at a time and save them in variables you want.
-
Mark Baker
- Forum Regular
- Posts: 710
- Joined: Thu Oct 30, 2008 6:24 pm
Re: Help with a smart function.
Code: Select all
function makeKey(&$item,$key,$prefix) {
$item = $prefix.$key;
}
$string = '19200';
$array_keys = range(1,strlen($string));
array_walk($array_keys,'makeKey','Char');
$varArray = array_combine($array_keys,str_split($string));
extract($varArray);