Solved

# seperate numbers

Posted on 2009-06-29
231 Views
Given somthing like: 859034, 482309, 7432890, 483902
Seperate it out as so:

\$1 = "859034";
\$2= "482309";

And so on ...
0
Question by:happpy36

LVL 19

Expert Comment

ID: 24741959
can you use an array?

\$data = "859034, 482309, 7432890, 483902"

\$my_array = explode(", ",\$data)
0

Author Comment

ID: 24741996
code that takes the first number in the list 859034, 482309, 7432890, 483902 and then stores it in the
variable, \$number, and then loops back and stores the second number, 482309, in \$number and so on
would work perfect for me.
0

LVL 5

Expert Comment

ID: 24742028
Are your numbers are as a string

\$nums = "859034, 482309, 7432890, 483902"

or arrays

\$nums = array(859034, 482309, 7432890, 483902);

0

LVL 5

Accepted Solution

Jagarm earned 200 total points
ID: 24742041
Is the following you are looking for?
``````//using array

\$nums = array(859034, 482309, 7432890, 483902);

foreach (\$nums as \$number) {

echo "\$number<br />";

}

//using string

\$nums = "859034, 482309, 7432890, 483902";

\$nums = split(",",\$nums);	//splitted by comma

foreach (\$nums as \$number) {

echo "\$number<br />";

}
``````
0

LVL 27

Assisted Solution

yodercm earned 190 total points
ID: 24742096
This echoes out the following:

859034
482309
7432890
483902
``````<?php

\$nums = '859034, 482309, 7432890, 483902';

\$array = explode(", ",\$nums);

for (\$i=0;\$i<count(\$array);\$i++)

{

\$number = \$array[\$i];

echo \$number;

echo "<br />";

}

?>
``````
0

LVL 14

Assisted Solution

Ionut A. Tudor earned 110 total points
ID: 24742180
maybe you want them to be stored for further references, see below
``````<?php

\$numbers = "859034, 482309, 7432890, 483902";

\$numbers_array = split(", ",\$numbers);

extract(\$numbers_array, EXTR_PREFIX_ALL, "number");

echo \$number_0;

echo "\n<br>";

echo \$number_1;

echo "\n<br>";

echo \$number_2;

echo "\n<br>";

echo \$number_3;

?>
``````
0

## Featured Post

### Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

#### Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!