Back to Basics. Learning PHP for Development

No Comments

[vc_row css=”.vc_custom_1511591812110{background-color: #ebebeb !important;}”][vc_column width=”1/2″][vc_custom_heading text=”PHP Tags: Opening & Closing Tags” font_container=”tag:h2|text_align:center|color:%23000000″ google_fonts=”font_family:Alef%3Aregular%2C700|font_style:400%20regular%3A400%3Anormal”][/vc_column][vc_column width=”1/2″][vc_message message_box_style=”solid” message_box_color=”blue”]A PHP Script starts with <?php and ends with ?>[/vc_message][/vc_column][/vc_row][vc_row][vc_column][vc_column_text][/vc_column_text][vc_separator color=”mulled_wine” style=”double” border_width=”2″][/vc_column][/vc_row][vc_row css=”.vc_custom_1511591812110{background-color: #ebebeb !important;}”][vc_column width=”1/2″][vc_custom_heading text=”Displaying Text with echo()” font_container=”tag:h2|text_align:center|color:%23000000″ google_fonts=”font_family:Alef%3Aregular%2C700|font_style:400%20regular%3A400%3Anormal”][/vc_column][vc_column width=”1/2″][vc_message message_box_style=”solid” message_box_color=”blue”]<?php echo “Hello world!”; ?>[/vc_message][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]The echo() function outputs one or more strings.

echo is not actually a function, so you are not required to use parentheses with it. echo (unlike some other language constructs) does not behave like a function, so it cannot always be used in the context of a function.

[/vc_column_text][vc_separator color=”mulled_wine” style=”double” border_width=”2″][/vc_column][/vc_row][vc_row css=”.vc_custom_1511591812110{background-color: #ebebeb !important;}”][vc_column width=”1/2″][vc_custom_heading text=”Learning PHP Variables: $variable ” font_container=”tag:h2|text_align:center|color:%23000000″ google_fonts=”font_family:Alef%3Aregular%2C700|font_style:400%20regular%3A400%3Anormal”][/vc_column][vc_column width=”1/2″][vc_message message_box_style=”solid” message_box_color=”blue”]<?php $firstname = ‘Anirudh’; $age = 29; ?>[/vc_message][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume).

Rules for PHP variables:

  • A variable starts with the $ sign, followed by the name of the variable
  • A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive ($age and $AGE are two different variables)

[/vc_column_text][vc_separator color=”mulled_wine” style=”double” border_width=”2″][/vc_column][/vc_row][vc_row css=”.vc_custom_1511591812110{background-color: #ebebeb !important;}”][vc_column width=”1/2″][vc_custom_heading text=”Learning PHP Data Types” font_container=”tag:h2|text_align:center|color:%23000000″ google_fonts=”font_family:Alef%3Aregular%2C700|font_style:400%20regular%3A400%3Anormal”][/vc_column][vc_column width=”1/2″][vc_message message_box_style=”solid” message_box_color=”blue”]boolean, string, integer, float…[/vc_message][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]

PHP supports ten primitive types.
Four scalar types:

  • boolean
  • integer
  • float (floating-point number, aka double)
  • string

Four compound types:

  • array
  • object
  • callable
  • iterable

And finally two special types:

  • resource
  • NULL

[/vc_column_text][vc_separator color=”mulled_wine” style=”double” border_width=”2″][/vc_column][/vc_row][vc_row css=”.vc_custom_1511591812110{background-color: #ebebeb !important;}”][vc_column width=”1/2″][vc_custom_heading text=”Control structures / Conditions” font_container=”tag:h2|text_align:center|color:%23000000″ google_fonts=”font_family:Alef%3Aregular%2C700|font_style:400%20regular%3A400%3Anormal”][/vc_column][vc_column width=”1/2″][vc_message message_box_style=”solid” message_box_color=”blue”]if, else, elseif, else if conditions[/vc_message][/vc_column][/vc_row][vc_row][vc_column][vc_column_text][/vc_column_text][vc_separator color=”mulled_wine” style=”double” border_width=”2″][/vc_column][/vc_row][vc_row css=”.vc_custom_1511591812110{background-color: #ebebeb !important;}”][vc_column width=”1/2″][vc_custom_heading text=”Arthimetic Operators” font_container=”tag:h2|text_align:center|color:%23000000″ google_fonts=”font_family:Alef%3Aregular%2C700|font_style:400%20regular%3A400%3Anormal”][/vc_column][vc_column width=”1/2″][vc_message message_box_style=”solid” message_box_color=”blue”]Addition, Subtraction, Multiplication….[/vc_message][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]

Example Name Result
+$a Identity Conversion of $a to int or float as appropriate.
-$a Negation Opposite of $a.
$a + $b Addition Sum of $a and $b.
$a – $b Subtraction Difference of $a and $b.
$a * $b Multiplication Product of $a and $b.
$a / $b Division Quotient of $a and $b.
$a % $b Modulo Remainder of $a divided by $b.
$a ** $b Exponentiation Result of raising $a to the $b‘th power. Introduced in PHP 5.6.

[/vc_column_text][vc_separator color=”mulled_wine” style=”double” border_width=”2″][/vc_column][/vc_row][vc_row css=”.vc_custom_1511591812110{background-color: #ebebeb !important;}”][vc_column width=”1/2″][vc_custom_heading text=”Comparison Operators” font_container=”tag:h2|text_align:center|color:%23000000″ google_fonts=”font_family:Alef%3Aregular%2C700|font_style:400%20regular%3A400%3Anormal”][/vc_column][vc_column width=”1/2″][vc_message message_box_style=”solid” message_box_color=”blue”]equal, identical, not equal, less than….[/vc_message][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]

Example Name Result
$a == $b Equal TRUE if $a is equal to $b after type juggling.
$a === $b Identical TRUE if $a is equal to $b, and they are of the same type.
$a != $b Not equal TRUE if $a is not equal to $b after type juggling.
$a <> $b Not equal TRUE if $a is not equal to $b after type juggling.
$a !== $b Not identical TRUE if $a is not equal to $b, or they are not of the same type.
$a < $b Less than TRUE if $a is strictly less than $b.
$a > $b Greater than TRUE if $a is strictly greater than $b.
$a <= $b Less than or equal to TRUE if $a is less than or equal to $b.
$a >= $b Greater than or equal to TRUE if $a is greater than or equal to $b.
$a <=> $b Spaceship An integer less than, equal to, or greater than zero when $a is respectively less than, equal to, or greater than $b. Available as of PHP 7.

[/vc_column_text][vc_separator color=”mulled_wine” style=”double” border_width=”2″][/vc_column][/vc_row][vc_row css=”.vc_custom_1511591812110{background-color: #ebebeb !important;}”][vc_column width=”1/2″][vc_custom_heading text=”Logical Operators” font_container=”tag:h2|text_align:center|color:%23000000″ google_fonts=”font_family:Alef%3Aregular%2C700|font_style:400%20regular%3A400%3Anormal”][/vc_column][vc_column width=”1/2″][vc_message message_box_style=”solid” message_box_color=”blue”]and, or, not…[/vc_message][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]

Example Name Result
$a and $b And TRUE if both $a and $b are TRUE.
$a or $b Or TRUE if either $a or $b is TRUE.
$a xor $b Xor TRUE if either $a or $b is TRUE, but not both.
! $a Not TRUE if $a is not TRUE.
$a && $b And TRUE if both $a and $b are TRUE.
$a || $b Or TRUE if either $a or $b is TRUE.

[/vc_column_text][vc_separator color=”mulled_wine” style=”double” border_width=”2″][/vc_column][/vc_row][vc_row css=”.vc_custom_1511591812110{background-color: #ebebeb !important;}”][vc_column width=”1/2″][vc_custom_heading text=”While loop” font_container=”tag:h2|text_align:center|color:%23000000″ google_fonts=”font_family:Alef%3Aregular%2C700|font_style:400%20regular%3A400%3Anormal”][/vc_column][vc_column width=”1/2″][vc_message message_box_style=”solid” message_box_color=”blue”]while expression is true: continue[/vc_message][/vc_column][/vc_row][vc_row][vc_column][vc_column_text]The meaning of a while statement is simple. It tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to TRUE. The value of the expression is checked each time at the beginning of the loop, so even if this value changes during the execution of the nested statement(s), execution will not stop until the end of the iteration (each time PHP runs the statements in the loop is one iteration). Sometimes, if the whileexpression evaluates to FALSE from the very beginning, the nested statement(s) won’t even be run once.

[/vc_column_text][vc_separator color=”mulled_wine” style=”double” border_width=”2″][/vc_column][/vc_row][vc_row][vc_column][/vc_column][/vc_row]

About us and this blog

We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

Subscribe to our newsletter!

More from our blog

See all posts

Leave a Reply