PHP - Can you help change this function slightly?

Posted by Joe on Stack Overflow See other posts from Stack Overflow or by Joe
Published on 2010-03-24T05:00:58Z Indexed on 2010/03/24 5:03 UTC
Read the original article Hit count: 187

Filed under:

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.

© Stack Overflow or respective owner

Related posts about php