[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
Re: Array inside an Array...
What do you mean? :confused:
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)
Re: Array inside an Array...
wait, i think i found it; i should have used:
PHP Code:
{$files[$randnum[$i]]}
Re: [resolved, i think]Array inside an Array...
That syntax is legal in PHP. What kind of error was it throwing?
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
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]]}");
Re: [resolved, i think]Array inside an Array...
ya, that is what i found out, if you read the other pages, but thanks anway