PHP : The Basics
October 26, 2016 ·
3 mins read
Categories:
What is PHP? php stands for Hypertext Preprocessor. We have posted a lot about the python web development framework Django. It is somewhat similar to Django. PHP is the most widely used language for the server. It is used for handling the server. It is also used to interact with your database so that you can save the data for future use. PHP is also open source and free to use. PHP is very easy to learn that is why many developers believe that every new developer ;learn this as the first language. Installation Installation of PHP is very simple and can be done easily. Just go to this link( http://php.net). Usage You have to insert starting and ending PHP tags in the html where ever you want to run some PHP script. Whenever you want to run some php code save the file with the .php extension. For eg:- save this file as new.php and run using the server. STARTING TAG : <?php ENDING TAG : ?> Variables Variables are the most important thing that any language must have. Variables in PHP are assigned without specifying the type of the variable.
<?php
$age = 20;
$name = 'Ranvir Singh';
echo $name;
Ranvir Singh
on the browser.
String handling funtions
String data type has many build in functions which can be used to make our work easier. For studying such functions see this post.
CONSTANTS
Constants are the variables whoes values never change during the execution of the program. Similarly PHP constants are used for similar purposes. define keyword is used to declare a constant.
SYNTAX:
define(“variable_name”, “Value_of_the_variable”, “case-insensitive( true/false)”);
case-insensitive is used if you want to make it case insensitive.
Conditional statements
- if
- if-else
- if-elif
- nested if
- switch statements
- while
- do while
- for
- for each
'; } ?>Function Functions are also similar to other languages. SYNTAX:
function functioname(){ //.... Somestuff return some_variable; } echo functionname();Arrays There are three types of arrays in PHP.
- Indexed Array : Accessed using the numbers
- Associative Array : Elements are accessed using the programmer given values
- Multi-dimensional Array : Similar to matrices.
echo count($arrayname);This function will print the total number of elements in an array. That’s it for now. With the provided knowledge you can easily build anything that you want. Think of something that you want to build. If you get any problem ask below.
Please share your Feedback:
Did you enjoy reading or think it can be improved? Don’t forget to leave your thoughts in the comments section below! If you liked this article, please share it with your friends, and read a few more!