|
-
May 16th, 2005, 11:26 AM
#1
Thread Starter
Fanatic Member
[resolved, i think]Array inside an Array...
ok, i am helping someone out with some php code, but i cannot figure out how to put an array inside an array, i know how to do it in CGI but not php, here is the code:
PHP Code:
<table width="175" height="1" border="0" cellpadding="0" cellspacing="0" class="left">
<tr>
<td height="1" background="images/left_border.gif"><img src="images/spacer" width="175" height="1"></td>
</tr>
<tr>
<td align="center" valign="top">
<img src="images/left_rule.gif" width="170" height="1" vspace="3"></td>
</tr><?
$dir = 'images/left/';
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
if($filename == "Thumbs.db" || is_dir($filename)){
}else{
$files[] = $filename;
}
}
$nooffildi = count($files);
$nooffiles = ($nooffildi-1);
srand((double)microtime()*100000);
for($i=0; $i<=2; $i++){
$randnum[$i] = rand(0,$nooffiles);
while($files[$randnum[$i]] == ""){
$randnum[$i] = rand(0,$nooffiles);
}
//THIS LINE!!!
ecno "<tr>\n
<td align=\"center\" valign=\"top\"><img src=$dir" . //HERE>>// . "$files[$randnum[$i]]" . //<<HERE// . "width=\"175\" border=\"0\" class=\"iborder\"></td>\n
</tr>\n
<tr>\n
<td align=\"center\" valign=\"top\"><img src=\"images/left_rule.gif\" width=\"170\" height=\"1\" vspace=\"3\"></td>\n
</tr>\n";
}
echo "</table>\n";
ALSO, ther //HERE// is only there to show you where i am taling about
Last edited by ALL; May 16th, 2005 at 12:55 PM.
-
May 16th, 2005, 11:59 AM
#2
Re: Array inside an Array...
What do you mean?
-
May 16th, 2005, 12:31 PM
#3
Thread Starter
Fanatic Member
Re: Array inside an Array...
he sayes it comes up with an error when on this statment:
PHP Code:
$files[$randnum[$i]]
i looked into it, and in php you are not allowed to use []'s inside []'s
how can that be recodded to allow the Array $randnum (which contains numbers) to output the number into the Array $files.
$files is a list of the files in a directory, and $randnum is an array of random numbers (only 3 rand nums)
-
May 16th, 2005, 12:54 PM
#4
Thread Starter
Fanatic Member
Re: Array inside an Array...
wait, i think i found it; i should have used:
PHP Code:
{$files[$randnum[$i]]}
-
May 16th, 2005, 04:06 PM
#5
Re: [resolved, i think]Array inside an Array...
That syntax is legal in PHP. What kind of error was it throwing?
-
May 16th, 2005, 04:20 PM
#6
Thread Starter
Fanatic Member
Re: [resolved, i think]Array inside an Array...
hmmm... here i will give a link to the thread where he asked:
http://www.ahfb2000.com/webmaster_he...ead.php?t=4338
butwe got it fixed
-
May 16th, 2005, 04:31 PM
#7
Re: [resolved, i think]Array inside an Array...
That is because:
PHP Code:
echo("$dir$files[$randnum[$i]]");
Should be:
PHP Code:
echo("$dir{$files[$randnum[$i]]}");
-
May 16th, 2005, 05:38 PM
#8
Thread Starter
Fanatic Member
Re: [resolved, i think]Array inside an Array...
ya, that is what i found out, if you read the other pages, but thanks anway
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|