Using a function as the parameter for another function in PHP -
this may strange , doesn't work wanted check before gave on idea. essentially, i'm trying use results of function 1 of parameters function. example - function1($param1, function2($param1));.
the code i've included outputs want to, issue i'm having outputs in wrong order - rather outputting: logos, h2, form, h2, form; 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 user not logged in, display login form if(!isset($_session[$uss])){ $nav = li('', require_once 'log_in.php'); // otherwise provide user information , 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 updates.'). li($lks, '<a href="task_list.php" class="'.$lks.'">task list</a>'). li($dss, 'tasks completed.'). li($lks, '<a href="logout.php" class="'.$lks.'">log out</a>'). li($dss, 'time 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 work around this? or not possible do?
the problem echoing results output. instead should use li
, ul
functions build , return
string caller echo out or pleases. therefore ul
and li
functions should become:
function ul($c, $p){ return '<ul class="'.$c.'">'.$p.'</ul>'; } function li($c, $p){ return '<li class="'.$c.'">'.$p.'</li>'; }
you call li
many times doing set $nav
. put together, in final call have:
echo ul('navigation', '<!--before breakpoint logo-->'. li('before_breakpoint_logo', '<a href="index.php"> <img src="logo.png" class="before_breakpoint_logo" /></a>'). $nav);
Comments
Post a Comment