Jump to content

[SOLVED] extarct and assign value


didgydont

Recommended Posts

hi all

not real sure about how to describe this one

basicly i have a serial number that can be 6 to 15 characters and i need to make each section a value

eg

5j39n2 needs to make $v1 = 5; $v2 = j; $v3 = 3; $v4 = 9; $v5 = n; $v6 = 2;

but one with 15 characters needs to go to

$v1 to $v15

any ideas

 

Link to comment
https://forums.phpfreaks.com/topic/122984-solved-extarct-and-assign-value/
Share on other sites

Store the characters in an array rather than a separate variable. Otherwise you have to keep track of how many variables you've created and it gets clumsy.

 

$str = '5j39n2';
$c = array();
for($x=0;$x<strlen($str);$x++){
$c[] = $str[$x];
}
echo '<pre>'.print_r($c,1).'</pre>';

 

Edit: Or, if you're using PHP 5, there's a function to do it for you:

 

$str = '5j39n2';
$c = str_split($str);
echo '<pre>'.print_r($c,1).'</pre>';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.