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 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/
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
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.
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.
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.
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. :)
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/
.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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.
|
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...
|
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...
|
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
|
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...
|
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
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |