tags:

views:

50

answers:

1

I have the following function I modified based off someone elses function:

       function showCombinations($string, $nameString, $linkParts, $i){
            $wordDivider = "/"; //the divider between the words/values

            if ($i >= count($linkParts)){
                echo "<a href='".trim($string)."'>".trim($nameString)."</a>, ";
            } else {
                foreach ($linkParts[$i] as $currentTrait){

                    if ($currentTrait['name']=="urltext"){
                        $currentNameStringName=""; //ignore
                    } else {
                        $currentNameStringName=$currentTrait['name'];
                    }

                    if ($nameString!=""){
                        $currentNameString=$nameString." - ".$currentNameStringName;
                    } else {
                        $currentNameString=$nameString.$currentNameStringName;
                    }
                    showCombinations($string.$currentTrait['value'].$wordDivider, $currentNameString, $linkParts, $i + 1);
                }


            }
        }
        showCombinations('', '', $linkParts, 0);

All I need to change this to do is, instead of "ECHO", I want it to build up the combination and so I can do:

        $result = showCombinations('', '', $linkParts, 0);
        echo $result;

I need it this way because I have to modify that $result, not just echo it.

+2  A: 
function showCombinations($string, $nameString, $linkParts, $i){
    $wordDivider = "/"; //the divider between the words/values
    $result = '';

    if ($i >= count($linkParts)){
        $result .= "<a href='".trim($string)."'>".trim($nameString)."</a>, ";
    } else {
        foreach ($linkParts[$i] as $currentTrait){

            if ($currentTrait['name']=="urltext"){
                $currentNameStringName=""; //ignore
            } else {
                $currentNameStringName=$currentTrait['name'];
            }

            if ($nameString!=""){
                $currentNameString=$nameString." - ".$currentNameStringName;
            } else {
                $currentNameString=$nameString.$currentNameStringName;
            }
            $result .= showCombinations($string.$currentTrait['value'].$wordDivider, $currentNameString, $linkParts, $i + 1);
        }


    }

    return $result;
}

$result = showCombinations('', '', $linkParts, 0);
echo $result;
Coronatus
oops, you forgot to return $result;
dar7yl
oops... thanks :D
Joe
doh.. anyone know how to return it as an array instead of a string?
Joe
nvm I figured it out lol
Joe