下面是我的代码。这段代码读取一个包含大约100个学生配置文件的csv文件。这些配置文件在这个HTML页面中以幻灯片的形式显示-- http://www.depts.ttu.edu/honors/medallion-ceremony/test/。我想显示一个广告幻灯片为每5个配置文件。请帮帮我!
$profiles = csv_to_array($_SERVER['DOCUMENT_ROOT'].'/...../profiles.csv');
function csv_to_array($filename, $delimiter=',', $enclosure='"', $escape = '\\')
{
if(!file_exists($filename) || !is_readable($filename)) return false;
$header = null;
$data = array();
$lines = file($filename);
foreach($lines as $line) {
$values = str_getcsv($line, $delimiter, $enclosure, $escape);
if(!$header)
$header = $values;
else
$data[] = array_combine($header, $values);
}
return $data;
}
function displayProfiles($limit=100)
{
global $profiles;
$count = 1;
foreach ($profiles as $profile)
{
if ($count <= $limit)
{
displayProfile($profile);
$count++;
}
}
}
function displayProfile($profile) {.....}发布于 2018-04-12 01:31:32
你可以在你所在的地方签入你的displayProfiles函数。使用模运算符http://php.net/manual/en/language.operators.arithmetic.php
然后你可以在你的循环中做类似这样的事情:
if($count % 5 == 0) {
displayAdvertisement();
}https://stackoverflow.com/questions/49780573
复制相似问题