我怎样才能使.$i.
div id - 取决于它的值?
当我检查源时,div id 总是ImgDiv- 0
,我怎样才能使它成为 1,2,3 ?
顺便说一句,这段代码生成了 3 个 div。这只是代码的一部分。printf 在最后,我只需要编辑这个块。
如果您需要其余代码,我很乐意发布
这些解决方案都不起作用:(也许如果我发布完整的代码?
<?php
$max = 3;
for ($i=0; $i<= $max; $i++) {
define('RANDOM_IMAGES_COUNT2',3);
define('RANDOM_IMAGES_FORMAT2', '<div id="imgDiv-' .$i. '"style="width:170px;height:auto;float:left;text-align:center;top"><img src="%s" style="border-style:solid;border-width:2px; border-color:black;"/><a href="%s" alt="%s" title2="%s">%s</a></div>');
}
#------------------------------------------------------------------------------
$images = array (
array ( 'title2' => 'Test 2', 'src2' => 'pic2.jpg', 'href2' => 'http://mylink.com/path/','text2' => 'Hello' ),
array ( 'title2' => 'Test 2', 'src2' => 'pic7.jpg', 'href2' => 'http://mylink.com/path/','text2' => 'Hello2' ),
array ( 'title2' => 'Test 2', 'src2' => 'pic9.jpg', 'href2' => 'http://mylink.com/path/','text2' => 'Hello2' ),
array ( 'title2' => 'Test 2', 'src2' => 'pic5.jpg', 'href2' => 'http://mylink.com/path/','text2' => 'Hello2' ),
array ( 'title2' => 'Test 2', 'src2' => 'pic3.jpg', 'href2' => 'http://mylink.com/path/','text2' => 'Hello3' )
);
#------------------------------------------------------------------------------
if ( count($images) < RANDOM_IMAGES_COUNT2 ) {
trigger_error('Not enough images given', E_USER_WARNING);
exit;
}
#------------------------------------------------------------------------------
for ($i = 0; $i < RANDOM_IMAGES_COUNT2; $i++) {
shuffle($images);
$tmp = array_shift($images);
printf( RANDOM_IMAGES_FORMAT2, $tmp['src2'], $tmp['href2'], $tmp['title2'], $tmp['title2'],$tmp['text2'] ); }
?>