Programming Lessons

[PHP]Let’s Try Connecting Letters! [Programming for Kids and Above #6]

Hello!

I’m kat, the manager of ‘kat’s blog.’

This time, which is the sixth installment of the ‘Programming Lessons’ series, I will be talking about handling letters and variables.

Up until last time, programming-wise we’ve been going over putting letters into variables.

However, for letters and variables, it is also possible to connect more letters and variables in the middle.

Let’s learn about how to do that this time!

What we will use this time

The programming language we will use this time

This time we will use the following programming language to write out a program.

・PHP

The programming environment we will use this time

Let’s use the paiza website which is listed below for executing the program.

paiza website

For those who are using this website for the first time, the way to use it is listed in the page below, so please check it out.

How to use paiza.io[Basics][Programming with Your Browser][PHP]Hello, I'm kat, the manager of 'kat's blog.' This time I would like ...

Let’s connect letters with letters

Without further ado, allow me to explain how to connect letters with letters.

Write out the source code as shown below, and execute it.

 <?php
  
 $message = "Hello." . "Mr.Bobby.";
 echo $message;

Then the result will show up as follows.

Hello.Mr.Bobby.

~Explanation~

$message = "Hello." . "Mr.Bobby.";

The letters have been connected, and been put into an array.

You can tell that there is a ‘. (dot)‘ between “Hello.” and “Mr.Bobby.”

Actually for PHP, you can connect letters simply by putting this ‘. (dot)’ in between.

echo $message;

The letters that have been connected are displayed.

Here, ‘Hello.’ and ‘Mr.Bobby.’ are connected and

Hello.Mr.Bobby.

will be displayed.

✓ Point

When you connect letters with letters, a ‘. (dot)’ is used.

Let’s connect letters with variables

Earlier we connected letters with letters, but let’s connect letters with variables this time.

First, let’s take a look at the source code.

<?php
  
 $name = "Mr.";
 $message = "Hello.".
 $name . "Bobby." ;
 echo $message;

Once executed, the result will also be as the following.

Hello.Mr.Bobby.

~Explanation~

$name = "Mr.";
$message = "Hello." . $name . "Bobby." ;

First, in the ‘$name’ variable, the title ‘Mr.’ is entered.

And in the next row, ‘Hello.’ and ‘$name’ and ‘Bobby.’ are connected by a ‘. (dot)’.

As you probably know already, just like when you connect letters with letters, you also use a ‘. (dot)’ when you connect letters with variables.

For this time ‘Bobby’ is in ‘$name,’ so the execution result will be all of them put together and it will be,

Hello.Mr.Bobby.

will be displayed.

✓ Point

Even when connecting letters with variables, and variables with variables , a ‘. (dot)’ is used.

Final thoughts

Thank you for reading to the end of this lesson this time as well.

This time we learned how to connect letters with letters, and letters with variables.

The process of connecting letters and variables is used often when doing loop processing, so let’s make sure to remember it.

We will start learning about loop processing from the next article, so please look forward to it!

See you next time!


ABOUT ME
kat
プログラマー歴7年、2歳の子供を持つパパです。 興味のあることはプログラミングや今後のIT技術などです。 趣味でオンラインカードゲームのサイトを運営しております。 プログラミングを通して社会に貢献していきたいです。