This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Objects in PHP Forum

View Course » View Exercise

892 points
Cf943138e3af6f413d4cca321cb043da?s=140&d=retro
Submitted by
RajiReddy
over 2 years ago

How to get the 2 outputs in different lines? And Can't we use ordered and unordered lists here?

<!-- Your code here -->
<?php
class Person{
public $isAlive=true;
public $firstname;
public $lastname;
public $age;

        public function __construct($firstname,$lastname,$age){
            $this->firstname=$firstname;
            $this->lastname=$lastname;
            $this->age=$age;
        }
    }

    $teacher=new Person("boring","always",12345);
    $student=new Person("kdow","oweie",22);

    print $teacher->isAlive;

    echo $student->age;

    ?>
  </p>

1 vote

permalink

I dont know if it works by print but it works by echo.

echo nl2br ("$student->age \n ");

echo nl2br ("{$teacher->greet()} \n");
You need the { } because there is a method.

172 points
553667c3e39efec3bf00026d_467163749
Submitted by
Violent_Silence
over 2 years ago

2 Comments

Cf943138e3af6f413d4cca321cb043da?s=140&d=retro RajiReddy over 2 years ago

Thanks! It also works with print

553667c3e39efec3bf00026d_467163749 Violent_Silence over 2 years ago

:) You're welcome :)