0

Its my first time trying this soo i am not sure it its going to correct way or how i could do something like this!! But what i want is an function with PHP and HTML together something like this.

function hoofdMenu1()
    {
        return '
        <!-- Columns are always 50% wide, on mobile and desktop -->
    <div class="container">
    <div id="hoofdmenu" class="col-xs-12  col-sm-2 col-md-2 col-lg-2">
                    <ul class="nav nav-pills nav-stacked">

        foreach($aMenu as $entry)  
        {
            foreach($entry as $key)
            {
                $sClass='';
                if($entry["page"] == $_GET['page'] ) :
                $sClass= 'active';
                endif; 
                echo '
                <li class="'.$sClass.'" role="presentation"><a
                href="index.php
                page='.$entry["page"].'">'.$entry["title"].'</a></li>'; 
                break;
            }
        }
    }

I know this is bad, but i am looking for something like this that when you call the function it do work like it would normaly do.

1
  • 1
    Since it's your first time: I would strongly advise you not to use PHP and HTML in a mixture like this. I's good to know that before you embed this in multiple products. Commented Jan 18, 2016 at 12:57

2 Answers 2

1
function hoofdMenu1()
    {
       $html = ' <div class="container">';
        $html .= ' <div id="hoofdmenu" class="col-xs-12  col-sm-2 col-md-2 col-lg-2">';
        $html .= ' <ul class="nav nav-pills nav-stacked">';

        foreach($aMenu as $entry)  
        {
            foreach($entry as $key)
            {
                $sClass='';
                if($entry["page"] == $_GET['page'] ) :
                $sClass= 'active';
                endif; 
                $html .= '<li class="'.$sClass.'" role="presentation"><a href="index.php" page='.$entry["page"].'">'.$entry["title"].'</a></li>'; 
                break;
            }
        }
            $html .= '</ul></div></div>';
        return $html ; 

    }
Sign up to request clarification or add additional context in comments.

7 Comments

I get an 0 in return and not the content.
I got the Html code correct but when the PHP starts at foreach() nothing happends i dont get the content inside $aMenu
<?php echo var_dump($aMenu);?> check if $aMenu variable contain data or not.
I just did and i get the array just normal, only when i use it in the function it wont work.
make <?php global $aMenu ; ?>
|
0

Try as below :

<?php
function hoofdMenu1()
{
    $return_string = '<!-- Columns are always 50% wide, on mobile and desktop -->
                        <div class="container">
                            <div id="hoofdmenu" class="col-xs-12  col-sm-2 col-md-2 col-lg-2">
                                <ul class="nav nav-pills nav-stacked">';

    foreach($aMenu as $entry) 
    {
        foreach($entry as $key) 
        {
            $sClass='';
            if($entry["page"] == $_GET['page'] ) : $sClass= 'active'; endif; 

            $return_string .= '<li class="'.$sClass.'" role="presentation">
                                    <a href="index.php page='.$entry["page"].'">'.$entry["title"].'</a>
                               </li>';
            break;
        }
    }

    $return_string .= '</ul></div></div>';

    return $return_string;
}
?>

1 Comment

I got the Html code correct but when the PHP starts at foreach() nothing happends i dont get the content inside $aMenu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.