What are Arrays in PHP?

  1. Today we will be learning Arrays in PHP. With the help of Arrays, we can store multiple types of data in one container. There are different types of Arrays.
  2. In variables as you know we can store data but with a limitation of only one single data or value.
  3. I would say Arrays are variables with Superpowers! It’s the number 1 container in programming.
  4. Let’s open our code editor and start with a blank page – Open HTML, head, body, and PHP tags.
  5. Next step – write a variable. Example – $numberList
  6. To make this variable a array simply apply a array function i.e.  $numberList = array(); or $numberList = []; syntax array() or []
  7. Now simply try storing different values e.g. $numberList = array(25,264,52,’99’,348, ‘<h1>Hello</h1>’);
  8. Now carefully note that each value in the array is called index. And an index in the array starts with 0 which means in our example 25 is index 0, 264 is index 1, and so on.
  9. To see the structure of the array. There is a built-in function in PHP to see the structure. Try the “print_r” function to check the structure of the array
  10. Next how do we display array data? Answer – example echo $numberList [0];
  11. With this, you will be able to see value 25 displayed.
  12. Try changing the index value to see the displayed value change.
  13. Hope you had fun learning. Thank you for your time.

How to do Math in PHP

  1. In addition to Variables in PHP today we are going to talk about Math
  2. Yes, you can do calculations in PHP similar to what you do on your calculator
  3. Open your code editor and open a new file.
  4. Open an HTML, HEAD, and PHP Tags
  5. Between the PHP tags,
  6. You can do additions, subtractions, division, and multiplications
  7. For every function, use echo and then simply add, multiply or subtract. 
  8. Syntax for functions – (+ for addition), (- for subtraction), (* for multiplication) and (/ for division)
  9. We can also do calculations with multiple functions such as “echo 45 + 34 * 45 / 421 – 45;”
  10. I would like to also share with you on the order of operations. Please remember that multiplication and division go before addition and subtraction.
  11. For example – echo 5 + 5 * 10 will show as 55 and not 100 unless you place 5+5 in prentices like (5 + 5) * 10
  12. Also – You can save numbers as variables and use them for calculations. For example – $number1 = 12; and $number2 = 24;.  Echo $number1 + $number2;

What are the Variables in PHP?

  1. What is a variable:

Variables are like containers.

Elements used to store data

Use that data with Variable name

2. Example 

Open a blank code editor

Open doc type HTML

Open and close PHP tag <?php  ?>

Used the $ sign followed by the name of the variable and then ;

$name = ‘Ratan’; for numbers $numbers = 100;

  • How can we use the variable?
  • echo $name;
  1. Variables are case sensitive and will end up making them a different variable if different case.
  1. Data in variable – We can store many different data types
  1. String data type – Always in quotes (texts)
  2. Numbers – Does not have quotes
  3. Floating point numbers – ones with decimals. (takes more memory)
  1. Concatenation – . Dot between two variables will smash them together
  1. Assign HTML tag to a variable = $name = “<h1> HELLO</h1>”
  1. Imp: Can only assign one value to the variables.

What is PHP? Learn with me!

While HTML is a client-side language, PHP is a server-side scripting language. PHP earlier was known as Personal Home Page however, it is today, widely known as “Hypertext Pre-processor”

Why learn PHP?

As PHP is native to the web, you’ll be able to put simple projects online a lot quicker and with less difficulty, than you would be able to with some other languages, meaning you will see results for your efforts much quicker than if you were to learn another language.

Through this blog, I will be sharing with you my PHP learning journey. I am hopeful, that this will help others to learn as well.

Step 1 – To learn PHP language, you will have to configure a local development environment. Upon searching online, you will find many local development environment tools. These may be different for windows and MAC users. In my case, I am using XAMPP.

Step 2 – Download a code editor. Great if you already have one.

Step 3 – Create a new project.

How do you start writing PHP?

PHP code is embedded in HTML with tags <?php ?> There are however multiple ways to write PHP tag – <? ?>, <?= ?, <% %>. <? php ?> however is a universal command.

Always remember to us “;” to complete the command.

Using dynamic data: For how to have a element made available in all the pages without needing to added manually. Set a title – $tite = “Ratan Oberoi Official Site”; and to use to title in any page here is a example

What are comments and how to create – Comment is a message a reference for you and for others.

Types of comments: // example for only one line comments, /* example for multiple line comment */

How to setup a WordPress site on Namecheap.

Here is the step-by-step guide to setting up a project on Namecheap

Hello friends. Before we start, I am assuming that you have signed in and successfully purchased the hosting space with Namecheap.

1st Step – Go to the dashboard. Under recently active in your account, you will find 3 icons under Products. Hover on the center icon and you will see the option, “Go to CPanel”

CPanel is the control panel where all files and sites will eb managed from.

We are going to create the data base – If your going to write blogs, it needs to save the information for it to be persistent.

This is where WP will be storing the blogs.

To create the Database, first search Database. Ctrl+f search data base.

Under Databases you will find MySQL Databases.

1st thing we will do is to create the database so we need to name a database under create new database. Once entered name then hit create

Copy the database name and paste it in a notepad as name as database.

Next, create the user – This is to ensure that only certain users have an access.

Return to Namecheap. GO back and select the option to create new user.

Enter your preferred username which is consistent and easy for you to remember.

Create Password – Use the password auto generator.

Copy the username and password and store at a safe place. Save as Database user password.

Hit create user.  

Now close CPannel.

Now very important – we have to give the user the privileges to make any changes in the database.

So select the user and database and click Add.

Give all privileges.

Now – We will be downloading WordPress and set it up on our server.

Go to Google – Search – Download WordPress and download.

Now, go back to the NameCheap cPanel.

On the top left side – You will see a checkbox square icon which is the home icon.

Now since we already have the database created, we need to upload the WordPress on our server.

Look the File Manager on the top – Click on FileManager

Look for public HTML on the left panel, double click that. That is where the project will be served from.

Look for a upload radio button on the top. Click on upload.

Next – Brows/Drop the WordPress zip file there.

Wait until the upload progress turns green. Don’t assume its upload just when its 100%.

Close the upload window.

Go back to cPanel File manager – Look for the option to Reload and click and you will find the WordPress file. Double click and extract.

Once Extracted, delete the Zip.

We now need to ensure that not only the WordPress file but all its content need to be in the root.

For this – Get in the WordPress folder – Select All – Move to Public HTML. THis will move all the files to Root.

New delete the WP empty folder.

Look for Index.php

 New the next step is to setup WordPres.

To setup WordPress – Go to your website. Its gets setup automatically as you go to your website the first time.

It automatically finds the Index.php

It will automatically start the setup since the codes are already in the index.php by default.

When asked – Enter database name, user name and password.

Database host – local host. Tabel prefix – wp_

Click submit and then click Run the Installation.

Set the Title. Setup the site username.

Very Important – Save in a notepad the following details –

Site Details

Username: xxx

PW: xxx

Backend site: Your backend URL

Frontend: Your front end URL

WordPress has 2 major aspects – FrontEnd and BackEnd.

Congratulations on setting up your First project on Namecheap!