Jump to content

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>';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.