Say I have an array containing ten items, and I want to display them
in a table as follows:
5 4 3 2 1
10 9 8 7 6
What's the best way to loop through that array to do that? My
thinking gets me to create a loop for 5 through 1, repeated twice, and
the second time I add '5' to
Ashley M. Kirchner wrote:
Say I have an array containing ten items, and I want to display
them in a table as follows:
5 4 3 2 1
10 9 8 7 6
What's the best way to loop through that array to do that? My
thinking gets me to create a loop for 5 through 1, repeated twice, and
the
Ashley M. Kirchner wrote:
Say I have an array containing ten items, and I want to display
them in a table as follows:
5 4 3 2 1
10 9 8 7 6
What's the best way to loop through that array to do that? My
thinking gets me to create a loop for 5 through 1, repeated twice, and
the
?php
$arr = array(5, 4, 3, 2, 1, 10, 9, 8, 7, 6,);
echo 'table border=1';
echo 'tr';
for ($x=0,$y=sizeof($arr); $x$y; ++$x) {
echo td{$arr[$x]}/td;
if ($x == 4) {
echo
Brad Bonkoski wrote:
Something like this perhaps...
$arr = array(...);
$per_row = 5;
$elem = count($arr);
for($i=0; $i$elem; $i++) {
if( $i == 0 )
echo tr;
else if( $i % $per_row == 0 )
echo /trtr;
echo td$arr[$i]/td;
}
That simply displays things in order, 1 through 5,
If you know the array elements, you may not need to loop. Why not just echo
the particular array elements i.e. td?php echo $array[2]; ?/td for
example?
$arr = array(...);
$first_row = '';
$second_row = '';
for ($i=4; $i=0; $i--){
$first_row = $first_row . td{$arr[$x]}/td;
$second_row = $second_row . td{$arr[$x + 5]}/td;
}
print 'tr' . $first_row . '/tr';
print 'tr' . $second_row . '/tr';
On Nov 16, 2006, at 3:19 PM, Ashley M.
So in other words, you have an array like $arr = array
(1,2,3,4,5,6,7,8,9,10) but you want it to render on the page as:
5 4 3 2 1
10 9 8 7 6
right?
-D
On Nov 16, 2006, at 1:35 PM, Ashley M. Kirchner wrote:
Darrell Brogdon wrote:
$arr = array(5, 4, 3, 2, 1, 10, 9, 8, 7, 6,);
The
Darrell Brogdon wrote:
So in other words, you have an array like $arr =
array(1,2,3,4,5,6,7,8,9,10) but you want it to render on the page as:
5 4 3 2 1
10 9 8 7 6
right?
That would be correct. James Tu provided a solution that I think
will work. I'm always open to other suggestions of
At 1:19 PM -0700 11/16/06, Ashley M. Kirchner wrote:
Say I have an array containing ten items, and I want to display
them in a table as follows:
5 4 3 2 1
10 9 8 7 6
What's the best way to loop through that array to do that? My
thinking gets me to create a loop for 5 through 1,
At 11/16/2006 12:19 PM, Ashley M. Kirchner wrote:
Say I have an array containing ten items, and I want to display
them in a table as follows:
5 4 3 2 1
10 9 8 7 6
What's the best way to loop through that array to do that? My
thinking gets me to create a loop for 5 through 1,
OK so I've done this hundreds of times, but this time I cannot get it to
work.
Please cast an eye over the following code and output and tell me why $k and
$v are not being set:
Code:
-
$ser = array( 'first', 'second', 'third', 'fourth', 'fifth' );
reset($ser);
I meant $key and $val of course :o)
- Kev
-Original Message-
From: Kevin Porter [SMTP:[EMAIL PROTECTED]]
Sent: 25 September 2002 12:00
To: '[EMAIL PROTECTED]'
Subject: [PHP] looping through array with list()/each()
OK so I've done this hundreds of times, but this time I
while ( list($key, $val) = each($ser) ); --- ; should not be here
-Original Message-
From: Kevin Porter [mailto:[EMAIL PROTECTED]]
Sent: 25 September 2002 12:13
To: Kevin Porter; '[EMAIL PROTECTED]'
Subject: RE: [PHP] looping through array with list()/each()
I meant $key and $val
Thank you, thank you, thank you.
And, er, D'oh! :o)
- Kev
-Original Message-
From: Karl Phillipson [SMTP:[EMAIL PROTECTED]]
Sent: 25 September 2002 12:13
To: [EMAIL PROTECTED]
Subject: RE: [PHP] looping through array with list()/each()
while ( list($key, $val) = each
15 matches
Mail list logo