0

I am trying to create custom function for Main Nav menu where I can only write menu item name and it will automatically wrap with

  • my content
  • Also I want variable where I can define url for each menu item.

    below is my code and giving me Parse error: syntax error, unexpected T_VARIABLE

    function the_main_nav($navlinks){
            echo '<nav>';
            echo '<ul>';
    
            $menuitem = $navlinks;
            $pieces = explode("," $menuitem);
            echo $pieces[0];
            echo $pieces[1];
    
            echo $menuitem;         
            echo '</ul>';
            return $pieces;
        }
    

    ------------------[Modified code]----------------------

    function the_main_nav($navlinks){
    echo '<nav>';
    echo '<ul>';
    
    $menuitem = $navlinks;
    $pieces = explode(" ",$menuitem);
    echo '<li>';
        echo $pieces[0];
        echo '</li>';
    echo '<li>';
        echo $pieces[1];
        echo '</li>';
    
    echo '</ul>';
        echo '</nav>';      
    }
    

    Now I want to make it dynamic like instead of getting value from [0] [1]..so on i want it will automatic generate as per the input character and create list with li

    1
    • 2
      explode("," $menuitem) ==> explode(",", $menuitem) Commented Mar 1, 2012 at 11:10

    2 Answers 2

    2

    You are missing the ,. You have to separate the argument of explode using comma.

    $pieces = explode(",", $menuitem);
    
    Sign up to request clarification or add additional context in comments.

    Comments

    0

    The explode() function breaks a string into an array. explode(separator, string) so in your code comma is missing.

    Comments

    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.