0

This may be strange and probably doesn't work but I wanted to check before I gave up on the idea. Essentially, I'm trying to use the results of a function as one of the parameters for another function. For example - function1($param1, function2($param1));.

The code I've included outputs everything I want it to, the only issue I'm having is that it outputs it in the wrong order - rather than outputting: logos, h2, form, h2, form; it outputs: form, h2, logos, form, h2.

// Display list
function ul($c, $p){
        echo '<ul class="'.$c.'">'.$p.'</ul>';
    }
    // Display list item
    function li($c, $p){
        echo '<li class="'.$c.'">'.$p.'</li>';
    }    
// Display navigation
        function nav(){
            require 'strings.php';
            // If the user is not logged in, display the login form
            if(!isset($_SESSION[$uss])){
                $nav = li('', require_once 'log_in.php');
            // Otherwise provide the user information and navigation
            }else{
                $nav = li($lks, $_SESSION[$uss][$uns]).
                       li($dss, $uss.' Id: '.$_SESSION[$uss]['id']).
                       li($dss, $uss.' Type: '.$_SESSION[$uss]['type']).
                       '<div id="display_projects_container">'.
                       require_once('display_projects.php').
                       '</div>'.
                       li($lks, '<a href="newsfeed.php" class="'.$lks.'">News Feed</a>').
                       li($dss, 'Check for updates.').
                       li($lks, '<a href="task_list.php" class="'.$lks.'">Task List</a>').
                       li($dss, 'Tasks to be completed.').
                       li($lks, '<a href="logout.php" class="'.$lks.'">Log Out</a>').
                       li($dss, 'Time for a burrito!');
            }
            echo '<div id="left_column">
                <!--After Breakpoint Logo-->
                <img src="logo.png" class="after_breakpoint_logo" />';
                ul('navigation', '<!--Before Breakpoint Logo-->'.
                                 li('before_breakpoint_logo', '<a href="index.php">
       <img src="logo.png" class="before_breakpoint_logo" /></a>').
                                 $nav);
                echo '</div><div id="content_container"><div id="content">';
        }

Is there a work around for this? Or is it just not possible to do?

4

1 回答 1

1

问题是您将结果回显到输出中。相反,您应该使用您的liul函数来构建return一个字符串,然后调用者将回显该字符串或随心所欲。因此,您的ulli功能应该成为:

function ul($c, $p){
    return '<ul class="'.$c.'">'.$p.'</ul>';
}

function li($c, $p){
    return '<li class="'.$c.'">'.$p.'</li>';
}    

li然后,您会在进行 set 时多次调用$nav。然后将它们放在一起,在最后的通话中,您将拥有:

echo ul('navigation', '<!--Before Breakpoint Logo-->'. 
    li('before_breakpoint_logo', '<a href="index.php">
       <img src="logo.png" class="before_breakpoint_logo" /></a>'). $nav);
于 2013-10-07T02:36:24.940 回答