Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #15585
| From | bobmct <r.mariotti@fdcx.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Refresher for array handling??? |
| Date | 2015-07-14 12:12 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <lvbaqa189n0e1ldtgg1de1vprbjvs46es2@4ax.com> (permalink) |
I have come across a rather old php program that develops a two
dimensional array's content then displays the accumulated contents at
the end.
After some upgrades to the latest php 5.x I started seeing "array to
string conversion errors". I am aware that these warings can be
suppressed but I'd rather take the time to reference the array
elements the correct way.
Here's a snippet of code as it looks now:
$frq = array(array);
.
// logic to accumulate statistics (all works fine based on dump of
array
.
.
// unload accummulated array as rows in a table
// iterate top to bottom using lowest to highest defined values
for ( $X=$_minimum; $X<=$_maximum; $X++) {
$Y = sprintf("%02d",$X);
$Y1 = sprintf("%u",$X);
print <<< EOD
<tr bgcolor="$bgcolor">
<td align="center"><img src="pix/balls/$Y.png" alt="$Y" ></td>
EOD;
// iterate left to right based on predefined columns
for ( $z=0; $z<=7; $z++) {
$Y2 = sprintf("%u",$z);
print <<< EOD
<td align="center">$frq[$Y1][$Y2]</td>
EOD;
}
}
.
.
as can be seen, I'm expanding the index X to a zero filled 2 character
string representative of the integer to properly select the image.
Also, the sprintf %u is to convert the index pointer to an unsigned
integer to point to each numbered index.
While this or something like this has been working for many years I
know there is a more standard way. I'm hoping someone will provide an
example of the "best" or at least "most conventional" method to
accomplish this task.
Thanks for any/all that can help.
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
Back to comp.lang.php | Previous | Next — Next in thread | Find similar | Unroll thread
Refresher for array handling??? bobmct <r.mariotti@fdcx.net> - 2015-07-14 12:12 -0400
Re: Refresher for array handling??? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-07-15 15:01 +0200
Re: Refresher for array handling??? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-07-15 15:03 +0200
Re: Refresher for array handling??? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-17 21:24 +0200
Re: Refresher for array handling??? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-07-20 16:30 +0200
Re: Refresher for array handling??? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-20 19:45 +0200
Re: Refresher for array handling??? Matthew Carter <m@ahungry.com> - 2015-07-20 22:36 -0400
Re: Refresher for array handling??? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-07-21 11:22 +0200
Re: Refresher for array handling??? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-21 13:30 +0200
Re: Refresher for array handling??? Erwin Moller <erwinmollerusenet@xs4all.nl> - 2015-07-21 14:03 +0200
Re: Refresher for array handling??? Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-21 01:01 +0000
Re: Refresher for array handling??? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-07-21 09:07 +0200
Re: Refresher for array handling??? "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-07-15 20:18 +0200
Re: Refresher for array handling??? Denis McMahon <denismfmcmahon@gmail.com> - 2015-07-17 02:51 +0000
csiph-web