I have been trying to draw a heart with star but only able to complete the upper part and the first left side. The right side remains vertical and i dont know why. Could someone please help me understand what i need to do? I have attached the image of what the result look like below.
<code> <?php
class hearts
{
public function firstLetter(string $name): string
{
$name = trim($name);
return $name[0];
}
public function initial(string $name): string
{
$name_to_upper = strtoupper($this->firstLetter($name));
return $name_to_upper . ".";
}
public function initials(string $name): string
{
$names = explode(" ", $name);
$fname = $names[0];
$lname = $names[1];
$firstname = $this->initial($fname);
$secondname = $this->initial($lname);
return $firstname . " " . $secondname;
}
public function pair(string $sweetheart_a, string $sweetheart_b)
{
$hearts = "";
$space = " ";
$star = "**";
$loversname = $sweetheart_a . " " . $sweetheart_b;
$lovers_initials = self::initials($loversname);
$hearts = str_repeat(" ", 10) . str_repeat(" *", 5) . str_repeat(" ", 5) . str_repeat(" *", 5) ."n";
print($hearts);
$y = 10;
$z = 20;
$a = "";
$b = "";
while ($y < 20) {
for ($i = 0; $i < $y; $i++) {
echo $space;
}
for ($j = 0; $j < 1; $j++) {
echo $star;
}
for ($k = 0; $k <= $z; $k++) {
echo $space;
}
for ($l = 0; $l < 1; $l++) {
echo $star . "n";
}
$z--;
$y++;
}
}
}
$obj = new hearts();
$obj->pair("John", "karen");
</code>
<code> <?php
class hearts
{
public function firstLetter(string $name): string
{
$name = trim($name);
return $name[0];
}
public function initial(string $name): string
{
$name_to_upper = strtoupper($this->firstLetter($name));
return $name_to_upper . ".";
}
public function initials(string $name): string
{
$names = explode(" ", $name);
$fname = $names[0];
$lname = $names[1];
$firstname = $this->initial($fname);
$secondname = $this->initial($lname);
return $firstname . " " . $secondname;
}
public function pair(string $sweetheart_a, string $sweetheart_b)
{
$hearts = "";
$space = " ";
$star = "**";
$loversname = $sweetheart_a . " " . $sweetheart_b;
$lovers_initials = self::initials($loversname);
$hearts = str_repeat(" ", 10) . str_repeat(" *", 5) . str_repeat(" ", 5) . str_repeat(" *", 5) ."n";
print($hearts);
$y = 10;
$z = 20;
$a = "";
$b = "";
while ($y < 20) {
for ($i = 0; $i < $y; $i++) {
echo $space;
}
for ($j = 0; $j < 1; $j++) {
echo $star;
}
for ($k = 0; $k <= $z; $k++) {
echo $space;
}
for ($l = 0; $l < 1; $l++) {
echo $star . "n";
}
$z--;
$y++;
}
}
}
$obj = new hearts();
$obj->pair("John", "karen");
</code>
<?php
class hearts
{
public function firstLetter(string $name): string
{
$name = trim($name);
return $name[0];
}
public function initial(string $name): string
{
$name_to_upper = strtoupper($this->firstLetter($name));
return $name_to_upper . ".";
}
public function initials(string $name): string
{
$names = explode(" ", $name);
$fname = $names[0];
$lname = $names[1];
$firstname = $this->initial($fname);
$secondname = $this->initial($lname);
return $firstname . " " . $secondname;
}
public function pair(string $sweetheart_a, string $sweetheart_b)
{
$hearts = "";
$space = " ";
$star = "**";
$loversname = $sweetheart_a . " " . $sweetheart_b;
$lovers_initials = self::initials($loversname);
$hearts = str_repeat(" ", 10) . str_repeat(" *", 5) . str_repeat(" ", 5) . str_repeat(" *", 5) ."n";
print($hearts);
$y = 10;
$z = 20;
$a = "";
$b = "";
while ($y < 20) {
for ($i = 0; $i < $y; $i++) {
echo $space;
}
for ($j = 0; $j < 1; $j++) {
echo $star;
}
for ($k = 0; $k <= $z; $k++) {
echo $space;
}
for ($l = 0; $l < 1; $l++) {
echo $star . "n";
}
$z--;
$y++;
}
}
}
$obj = new hearts();
$obj->pair("John", "karen");