I
I
Ivan Zhuk2020-08-24 18:19:12
PHP
Ivan Zhuk, 2020-08-24 18:19:12

OOP Users?

Guys Hello everyone, I have such a question, I just started to study oop
How to do so that I would not write more
$users->getInfo();
Tk I can have 1000 users and I can’t write like that 1000 times to display the entire username

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
  <title>ООП</title>
</head>
<body>
<?php

class User{
    public $name;
    public $email;
    public $city;
    public $password;

    public function __construct($name,$email,$city,$password)
    {
        $this->name = $name;
        $this->email = $email;
        $this->city = $city;
        $this->password = $password;
    }
    public function getInfo(){ ?>
        <table class="table">
  <thead>
    <tr>
      <th scope="col">Имя</th>
      <th scope="col">Email</th>
      <th scope="col">Город</th>
      <th scope="col">Пароль</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th scope="row">Id</th>
      <td><?php echo $this->name; ?></td>
      <td><?Php echo $this->email; ?></td>
      <td><?php echo $this->city; ?></td>
    </tr>
  </tbody>
</table>
  <?php   }
}
$users = new User('Иван','ivanzuk761@gmail.com','Киев',143);
$users->getInfo();


$users2 = new User('Руслам','ruslam.com','mocow',6489);
$users2->getInfo();

?>

</body>
</html>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ronald McDonald, 2020-08-24
@ivanzuk761

I just started learning OOP

Now start learning for cycles: www.php.su/learnphp/cs/?cycles

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question