Jump to content


  • Posts

  • Joined

  • Last visited

Posts posted by saltedm8

  1. Bit of an understatement lol, I'm weak on everything, but I'm trying with the resources I have to learn php, I get quite distracted, learning 3D techniques in cinema 4d, keeping up with design standards, adobe software and I have only just learned version control through git.. up until 3 months ago I knew nothing about scss for the example (went to uni as a mature student to get a degree in web/graphic design - 3 years out of this trade), and that's not counting that I am an avid gym goer and have an interest in political debate.. I am all over the place lol but, again, I am trying.. I am grateful for any guidance and help

  2. A Udemy course called 'learn object orintated php by building a complete website' I have not finished it yet, but I have viewed both the basic and advanced sections


    It probably does not help that I am a designer and have been away from php for at least 8 years.

  3. Got it! This is what I was trying to do, I really appreciate the help though it. thank you (the rest should be simple enough)

    class listing{
      public function list(){
        $list = func_get_args();
        foreach ($list as $lists)
          echo $lists;
    $listed = new listing();
    $listed->list('one ','two ','three ','four ');
    echo '</br>';
    $listed->list('five ','six ','seven ','eight ');
  4. I'm gonna bet that you if you had enabled php error checking it would have shown you the error in your code. Your for loop is not written correctly. "count($menuitems)"


    See my signature


    Actually, I have been using phpfiddle, although I did add that and did not get any error backs (except a phpfiddle ini set)


    One specific problem I see in your code is how you are using the class. perhaps that is the source of your problem and you are not explaining it well.

    $menu_items = new menu('one', 'two', 'three', 'four');

    You are setting $menu_items to the return value of the class instantiation, However, the constructor has no return value. Instead the constructor is outputting content to the page. You absolutely should have the class return the content instead of outputting it.


    To add to ginerjm's response, I don't see a need for a class either if it has only one purpose of creating the menu links. Perhaps just a function would do.

    function createMenuLinks($menuAry)
        foreach($menuAry as $label => $url)
            $menuHTML .= "<li><a href='{$url}'>{$label}</a></li>\n";
        return $menuHTML;
    $menuItems = array(
        'Home' => 'index.php',
        'About Us' => 'about.php',
        'Services' => 'services.php',
        'Contact Us' => 'contact.php'
    $menuLinks = createMenuLinks($menuItems);
    <ul class="menu">
        <?php echo $menuLinks; ?>


    Thanks, the reason for the class is simply one of practice, since I am only just learning classes, I am not using this in production, but the one way it could be used in production is a template where you could instantiate a class and place in the names of the links you want to put there directly without doing through the function as I am pretty sure this sort of issue will crop up when I know enough to build with it. Could not find anywhere that would cover this type of issue.

    class navigation {
        public $menuitems;
        public function menu_items($menuitems){
            echo $i;
    $my_menu = new navigation();
    $my_menu -> menu_items('one', 'two', 'three', 'four');

    produces nothing.

  6. No, sorry, I posted that in order to show the basic idea of the sorts of things I am trying.


    I have tried a loop and a foreach, but basically, I want a class where all I have to do is type 

    $menu_items = new menu('one', 'two', 'three', 'four');

    and it produces the amount of items i have stated there.. the only other thing my brain dead mind forgot was linking lol.. forgot to add those too.

  7. Hi


    I am trying to create a loop function so that whenever I add parameters to the $menu_items, it adds another menu item to the construct. 


    I have been trying for a couple of days, I think I need some direction to help me, I am struggling, I am fairly new to php and really new to classes and oop..  thanks

    class menu {
        public function __construct($menu){
            echo '<li>' . $menu . '<li>';
    $menu_items = new menu('one', 'two', 'three', 'four');


  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.