473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

What is best way to spit numbers into an array?

Looking for a function to split numbers into an array for use in a simple
graphical counter.

Objective:
$count = 12345
//want to end up with
$array[0]=1
$array[1]=2
$array[2]=3 //and so on then I can do this
$size=sizeof($array);
for ($r = 0; $r == $size; $r++) {
echo "<img border='0' src='_borders/$array[$r].gif'> ";
}

Note am using PHP4
Regards
Dynamo

Jul 17 '05 #1
8 2635
Carved in mystic runes upon the very living rock, the last words of
Dynamo of comp.lang.php make plain:
Objective:
$count = 12345
//want to end up with
$array[0]=1
$array[1]=2
$array[2]=3 //and so on then I can do this


$array = explode(' ', trim(chunk_split($count, 1, ' ')));

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #2
Dynamo <Dy***********@newsguy.com> wrote in
news:cp*********@drn.newsguy.com:
Looking for a function to split numbers into an array for use in a simple
graphical counter.

Objective:
$count = 12345
//want to end up with
$array[0]=1
$array[1]=2
$array[2]=3 //and so on then I can do this
$size=sizeof($array);
for ($r = 0; $r == $size; $r++) {
echo "<img border='0' src='_borders/$array[$r].gif'> ";
}


Maybe just do

for ($r=0;$r<strlen($count);$r++){
echo "<img border='0' src='_borders/". substr($count,$r,1) .".gif'> ";
}

or do you _need_ an array?

Oliver

Jul 17 '05 #3
Do this:

$count = "12345";

$array = array();

for ($i=0; $i<strlen($count); $i++) {
$array[] = $count[$i];
}


I believe this will work. You can access PHP strings as if it were an
array. I could be wrong, though, because I never actually had to do it.

Jul 17 '05 #4
Do this:

$count = "12345";

$array = array();

for ($i=0; $i<strlen($count); $i++) {
$array[] = $count[$i];
}


I believe this will work. You can access PHP strings as if it were an
array. I could be wrong, though, because I never actually had to do it.

Jul 17 '05 #5
In article <Xn****************************@63.223.5.251>, Oliver Spiesshofer
says...

Dynamo <Dy***********@newsguy.com> wrote in
news:cp*********@drn.newsguy.com:
Looking for a function to split numbers into an array for use in a simple
graphical counter.

Objective:
$count = 12345
//want to end up with
$array[0]=1
$array[1]=2
$array[2]=3 //and so on then I can do this
$size=sizeof($array);
for ($r = 0; $r == $size; $r++) {
echo "<img border='0' src='_borders/$array[$r].gif'> ";
}


Maybe just do

for ($r=0;$r<strlen($count);$r++){
echo "<img border='0' src='_borders/". substr($count,$r,1) .".gif'> ";
}

or do you _need_ an array?


No I don't necessarily need an array and your solution did the trick. Many
thanks.

Jul 17 '05 #6
In article <Xn**************************@216.196.97.132>, Alan Little says...

Carved in mystic runes upon the very living rock, the last words of
Dynamo of comp.lang.php make plain:
Objective:
$count = 12345
//want to end up with
$array[0]=1
$array[1]=2
$array[2]=3 //and so on then I can do this


$array = explode(' ', trim(chunk_split($count, 1, ' ')));


Thanks but Olivers solution worked without me having to use an array. However, I
will log it in my "Unused but I'm sure I'll need it in the future" folder. :)

Jul 17 '05 #7
Carved in mystic runes upon the very living rock, the last words of
Dynamo of comp.lang.php make plain:
Thanks but Olivers solution worked without me having to use an array.
However, I will log it in my "Unused but I'm sure I'll need it in the
future" folder. :)


Ah - silly me, answering your question rather than what you were trying to
do. :)

--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
Jul 17 '05 #8
.oO(Oliver Spiesshofer)
Maybe just do

for ($r=0;$r<strlen($count);$r++){
echo "<img border='0' src='_borders/". substr($count,$r,1) .".gif'> ";
}


Or

for ($r = 0; $r < strlen($count); $r++) {
echo "<img src='_borders/{$count{$r}}.gif' alt='{$count{$r}}'>";
}

Micha
Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
4
by: David | last post by:
Hello. I am looking for advice on what is "best practice" regarding looping through a form to check its checkboxes and associated data fields. Here is what I am trying to do (Here is the page...
47
by: Neal | last post by:
Patrick Griffiths weighs in on the CSS vs table layout debate in his blog entry "Tables my ass" - http://www.htmldog.com/ptg/archives/000049.php . A quite good article.
29
by: asj | last post by:
Can you guess what this is? http://www.blueboard.com/phone/apache_sept_2003.gif It's a history of the IIs "Titanic", which is being slowly and painfully sunk by the open source Apache web...
8
by: J. B. Moreno | last post by:
What's the best (i.e. fastest) way to find out if an array contains a given value? Other than looping, the only way I know to do it is to use an associative array/hash instead.... Is there a...
11
by: Angus Comber | last post by:
Hello I want to create a lookup table where I can store string keys: For example: 192.168.0.1 -> Purple 192.168.0.2 -> Blue 192.168.0.3 -> Red
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
29
by: calvert4rent | last post by:
I need to some sort of data type that will hold a listing of ID's and their counts/frequency. As I do some processing I get an ID back which I need to store and keep an accurate count for how many...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.