how would i implode a string of numbers, by the lenght.. like
if i had
123456789
and i wanted it to take 3 numbers and create an array.. like
123 - 456 - 789
how would i do that?
i tried to use a for() loop, but it seems that if i did
for($i = 0; $i < $thing; $i+3){}
it wouldn't work...
any ideas?
substring and arrays
Moderator: General Moderators
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
Code: Select all
$source = "123456789";
$source=number_format($source);
$arr = explode(',', $source);
foreach($arr as $ns)
print($ns.'<br/>');- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
- RandomEngy
- Forum Contributor
- Posts: 173
- Joined: Wed Jun 26, 2002 3:24 pm
- Contact:
Just wrote this script:
Code: Select all
<?php
$input = "14539592348725";
$segment_len = 4;
$result = array();
for( $i = 0; $i < strlen($input); $i += $segment_len)
$resultї] = substr($input, $i, $segment_len);
echo "<pre>";
var_dump($result);
echo "</pre>";
?>- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
i fixed it by doing this:
Code: Select all
for($i = 0; $i < $thing; $i++){
$x = $i * 8;
$sub = substr($foo, $x, 8);
$arrї] = $sub;
}