Php 当此函数循环时,创建一个20px的左填充

Php 当此函数循环时,创建一个20px的左填充,php,css,loops,Php,Css,Loops,如何格式化此代码块,以便每次发生此循环时, 它将每个超链接元素从左侧移动20px 它目前正在工作,但对整个部门来说,不是单个项目 示例: -链接1 --链接2 ---链接3 任何帮助都将不胜感激 $linkArray = array(); $thisDir = ''; $baseDir = ($htmlRoot == '') ? '' : $htmlRoot; for ($n=0; $n<count($dirArray); $n++) { $this

如何格式化此代码块,以便每次发生此循环时,
它将每个超链接元素从左侧移动20px

它目前正在工作,但对整个部门来说,不是单个项目

示例:
-链接1
--链接2
---链接3

任何帮助都将不胜感激

$linkArray = array();
    $thisDir = '';
    $baseDir = ($htmlRoot == '') ? '' : $htmlRoot;
    for ($n=0; $n<count($dirArray); $n++) {
        $thisDir .= $dirArray[$n].'/';
        $thisIndex = MPBCDirIndex($htmlRoot.$thisDir);
        $thisText = ($n == 0) ? $topLevelName : MPBCFixNames($dirArray[$n]);
        $thisLink = ($thisIndex != '') ? '<span style="padding-left:20px;"><a href="'.$thisDir.$thisIndex.'">'.$thisText.'</a></span>' : $thisText;
        if ($thisLink != '') $linkArray[] = $thisLink;
        }

    $results = (count($linkArray) > 0) ? implode($separator, $linkArray) : '';
$linkArray=array();
$thisDir='';
$baseDir=($htmlRoot==“”)?“”:$htmlRoot;
对于($n=0;$n 0)?内爆($separator,$linkArray):“”;

嗯,您已经在用$n变量计算迭代次数了。因此:

例如


for($n=0;$n将padding left属性硬编码为20px。如果希望它是($n*20),则需要使用变量。什么不使用列表并设置其样式?感谢各位的回复!Dagon,我将如何在这里实现列表?谢谢Ben,我也会尝试一下并让您知道!与我合作非常好Ben,感谢您的帮助。
  for ($n=0; $n<count($dirArray); $n++) {

    $pxvar = $n * 20;

    $thisDir .= $dirArray[$n].'/';
    $thisIndex = MPBCDirIndex($htmlRoot.$thisDir);
    $thisText = ($n == 0) ? $topLevelName : MPBCFixNames($dirArray[$n]);
    $thisLink = ($thisIndex != '') ? '<span style="padding-left:'.$pxvar.'px;"><a href="'.$thisDir.$thisIndex.'">'.$thisText.'</a></span>' : $thisText;
    if ($thisLink != '') $linkArray[] = $thisLink;


    }