In this research, you are asked to write about php programming language,
write a dummy paper to show all the required information about this language that might help readers with less knowledge to know how to use it. Use the following points to talk about your programming language:
- The historical background when, how this language began and,
what is the domain that it was used for.
- The category of this language, according to Language categories
in Chapter1.
- The primitive data types are available in the chosen
language.
- The operator precedence rules and the associative rules.
- The rules of naming variables (Case sensitivity, keywords), Show
examples. - Does the language support type checking?
- Write a set of code that shows how to implement:
* an array.
* a pointer/reference type.
* a union type.
* relation or Boolean expression.
* assignment statements: simple, unary, as an expression, and
multiple. * a kind of Selection statement.
* one type of iterative statement.
include more information as much as you see, that is appropriate. Show your skills and knowledge on how to write a scientific paper. Include all required information such as your information, references, a decent introduction, and the look of the overall document. .
Introduction to PHP
A script is a set of programming instructions that is interpreted at runtime. A scripting language is a language that interprets scripts at runtime. Scripts are usually embedded into other software environments. The purpose of the scripts is usually to enhance the performance or perform routine tasks for an application.
Server side scripts are interpreted on the server while client side scripts are interpreted by the client application.
PHP is an acronym for "PHP: Hypertext Pre processor", PHP is a widely-used, open source scripting language. PHP scripts are executed on the server.
PHP is a server side scripting that is interpreted on the server while JavaScript is an example of a client side script that is interpreted by the client browser. Both PHP and JavaScript can be embedded into HTML pages.
Pre Requisites to learn PHP : HTML, CSS and JavaScript.
History of PHP
PHP was created in 1995 by Rasmus Lerdorf and means Personal Home Page language. Ever since its beginning it has been one of the most intuitive programming languages used for the creation of dynamic web pages. Later, when the PHP team was formed, the parser was rewritten and PHP version 3.0 saw the light of day. The PHP 3 version was the first serious improvement of the PHP language, which fixed a lot of bugs and completely redesigned the PHP core. The meaning of the abbreviation was also changed to PHP Hypertext Preprocessor.
Ever since its beginning PHP has been one of the most intuitive programming languages used for the creation of dynamic web pages. PHP comes under scripting language.
Why PHP?
PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
PHP is compatible with almost all servers used today (Apache, IIS, etc.)
PHP supports a wide range of databases
PHP is free to download and use.
PHP is easy to learn and runs efficiently on the server side.
Primitive datatypes in PHP
PHP supports the following 8 data types:
Operator Precedence and Associativity
Here operators with the highest precedence appear at the top of the table, those with the lowest appear at the bottom. Within an expression, higher precedence operators will be evaluated first.
|
Operator Precedence |
Operator |
Associativity |
|
1. 1.Unary |
! ++ -- |
Right to left |
|
2. Multiplicative |
* / % |
Left to right |
|
3. Additive |
+ - |
Left to right |
|
4. Relational |
< <= > >= |
Left to right |
|
5. Equality |
== != |
Left to right |
|
6. Logical AND |
&& |
Left to right |
|
7. Logical OR |
|| |
Left to right |
|
8. Conditional |
?: |
Right to left |
|
9. Assignment |
= += -= *= /= %= |
Right to left |
Creating (Declaring) PHP Variables
In PHP, a variable starts with the $ sign, followed by the name of the variable:
Example:
<?php
$txt = "Hello world!";
$x = 5;
$y = 10.5;
?>
After the execution of the
statements above, the variable $txt will hold the
value Hello world!, the variable $x will
hold the value 5, and the variable $y
will hold the value 10.5.
PHP Variables
A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume).
Rules for PHP variables:
List of all PHP keywords
· abstract
· and
· Array()
· as
· break
· callable
· continue declare
· default
· die()
· do
· echo
· else
· elseif
· empty
· enddeclare
· endfor
· endforeach
· endif
· endswitch
· endwhile
· eval()
· exit()
· extends
· final
· finally
· for
· foreach
· function
· global
· goto
· if
· implements
· include
· include_once
· instanceof
· insteadof
· interface
· isset()
· list()
· namespace()
· new
· or
· private
· protected
· public
· require
· require_once
· return
· static
· switch
· throw
· trait
· try
· unset()
· use
· var
· while
· xor
· yield
· yield_form
PHP | gettype() Function
The gettype() function is an inbuilt function in PHP which is used to get the type of a variable. It is used to check the type of existing variable.
Syntax:
string gettype ( $var )
Parameter: This function accepts a single parameter $var. It is the name of variable which is needed to be checked for type of variable.
Example:
|
<?php // PHP program to illustrate gettype() function $var1 = true; // boolean value $var2 = 3; // integer value $var3 = 5.6; // double value $var4 = "Abc3462"; // string value $var5 = array(1, 2, 3); // array value $var6 = new stdClass; // object value $var7 = NULL; // null value $var8 = tmpfile(); // resource value echo gettype($var1)."\n"; echo gettype($var2)."\n"; echo gettype($var3)."\n"; echo gettype($var4)."\n"; echo gettype($var5)."\n"; echo gettype($var6)."\n"; echo gettype($var7)."\n"; echo gettype($var8)."\n"; |
Creating an Array in PHP
In PHP, the array() function is used to create an array:
array();
In PHP, there are three types of arrays:
Get The Length of an Array - The count() Function
The count() function is used to return the length (the number of elements) of an array:
Example
<?php
$cars = array("Volvo", "BMW", "Toyota");
echo count($cars);
?>
Reference Types in PHP
References in PHP are a means to access the same variable content by different names. They are not like C pointers; for instance, you cannot perform pointer arithmetic using them, they are not actual memory addresses, and so on. Instead, they are symbol table aliases. Note that in PHP, variable name and variable content are different, so the same content can have different names. The closest analogy is with Unix filenames and files - variable names are directory entries, while variable content is the file itself
As said before, references are not pointers. That means, the following construct won't do what you expect:
<?php
function foo(&$var)
{
$var =& $GLOBALS["baz"];
}
foo($bar);
?>
What happens is that $var in foo will be bound with $bar in the caller, but then re-bound with $GLOBALS["baz"]. There's no way to bind $bar in the calling scope to something else using the reference mechanism, since $bar is not available in the function foo (it is represented by $var, but $var has only variable contents and not name-to-value binding in the calling symbol table). You can use returning references to reference variables selected by the function.
Union in PHP
Ds\Set::union — Creates a new set using values from the current instance and another set
Example
public Ds\Set::union ( Ds\Set $set ) : Ds\Set
Creates a new set that contains the values of the current instance as well as the values of another set.
Logical / Boolean Operators in PHP
|
Operator |
Name |
Example |
Result |
|
|
And |
|
True if both $x and $y are true |
|
|
Or |
|
True if either $x or $y is true |
|
|
Xor |
|
True if either $x or $y is true, but not both |
|
|
And |
|
True if both $x and $y are true |
|
|
Or |
|
True if either $$x or $y is true |
|
|
Not |
|
True if $x is not true |
The following example will show you these logical operators in action:
Example
Run this code »
<?php
$year = 2014;
// Leap years are divisible by 400 or by 4 but not 100
if(($year % 400 == 0) || (($year % 100 != 0) && ($year % 4 == 0))){
echo "$year is a leap year.";
} else{
echo "$year is not a leap year.";
}
?>
PHP assignment operators
The PHP assignment operators are used with numeric values to write a value to a variable.
The basic assignment operator in PHP is "=". It means that the left operand gets set to the value of the assignment expression on the right.
x += y is same as x = x + y i.e, Addition
x -= y is same as x = x – y i.e, Subtraction
x *= y is same as x = x * y i.e, Multiplicaction
x /= y is same as x = x / y i.e, Division
x %= y is same as x = x % y i.e, Modulus
Example
< !DOCTYPE html>
<html>
<body>
<?php
$x = 20;
$x += 100;
echo $x;
?>
</body>
</html>
PHP Selection/Conditional Statements
In PHP we have the following conditional statements:
Example
<?php
$t = date("H");
if ($t < "20") {
echo "Have a good day!";
}
?>
<?php
$t = date("H");
if ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
<?php
$t = date("H");
if ($t < "10") {
echo "Have a good morning!";
} elseif ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
<?php
$favcolor = "red";
switch ($favcolor) {
case "red":
echo "Your favorite
color is red!";
break;
case "blue":
echo "Your favorite color is
blue!";
break;
case "green":
echo "Your favorite color is
green!";
break;
default:
echo "Your favorite color is neither
red, blue, nor green!";
}
?>
PHP Iterative statements/ Loops
Often when you write code, you want the same block of code to run over and over again a certain number of times. So, instead of adding several almost equal code-lines in a script, we can use loops.
Loops are used to execute the same block of code again and again, as long as a certain condition is true.
In PHP, we have the following loop types:
PHP while - loops
The while loop
executes a block of code as long as the specified condition is
true.
Syntax
while
(condition is true) {
code to be executed;
}
The example below displays the numbers from 1 to 5:
Example
<?php
$x = 1;
while($x <= 5) {
echo "The number is: $x <br>";
$x++;
}
?>
The PHP do...while Loop
The do...while loop will always execute the block of code once,
it will then check the condition, and repeat the loop while the
specified condition is true.
Syntax
do {
code to be executed;
} while (condition is true);
Examples
The example below first sets a variable $x to 1 ($x = 1). Then, the do while loop will write some output, and then increment the variable $x with 1. Then the condition is checked (is $x less than, or equal to 5?), and the loop will continue to run as long as $x is less than, or equal to 5:
<?php
$x = 1;
do {
echo "The number is: $x <br>";
$x++;
} while ($x <= 5);
?>
The PHP for Loop
The for loop is used when you know in advance how many
times the script should run.
Syntax
for (init counter; test
counter; increment counter) {
code to be executed for each iteration;
}
Parameters:
The example below displays the numbers from 0 to 10:
Example
<?php
for ($x = 0; $x <= 10; $x++)
{
echo "The number is: $x <br>";
}
?>
Example Explained
PHP foreach Loop
The foreach loop works only on arrays, and is used to loop
through each key/value pair in an array.
Syntax
foreach ($array as
$value) {
code to be executed;
}
For every loop iteration, the value of the current array element is assigned to $value and the array pointer is moved by one, until it reaches the last array element.
Examples
The following example will output the values of the given array ($colors):
Example
<?php
$colors = array("red", "green",
"blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
In this research, you are asked to write about php programming language, write a dummy paper...
Submissions are accepted in program codes in C
PROGRAMMING LANGUAGES COURSE ASSIGNMENT Design your own general purpose programming language which will be completely in english Your language design must include the following A general skeleton of a program State diagrams for the following (35 pts) . Identifier Unsigned integer Unsigned constant Constant Variable Factor and term rules similar to the ones given in your textbook Simple expression Compound expression . Parameter list Simple type 1D Array type Statement Block Loop...
Write a short paper about the Action Research Methodology. Define Action Research. Describe and explain the type of Action Research that will be used for the project building book store web application and it is done individually in college Describe how and explain why (reasons and justification) this approach is appropriate for project building book store web application The Proposal section must include a heading for each AR iteration (i.e., Iteration 1, Iteration 2, etc.). A summary under each heading...
C++
please
Project: Working with Text Write an object-oriented program the performs the following tasks: . Reads a text file provided along with this data and maintains it an object. Determines the number of characters and keeps in the object. Determines the number of words and retains the result in the object. Determines the number of paragraphs and keeps the result in the object. A possible class definition: class Textutil { string text = ** int words = @; int...
Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...
Plz help!! The programming
language is C and could you write comments as well?
Problem 2. Calculate Grades (35 points) Arrays can be used for any data type, such as int and char. But they can also be used for complex data types like structs. Structs can be simple, containing simple data types, but they can also contain more complex data types, such as another struct. So you could have a struct inside of a struct. This problem deals with...
C programming is the main one and pick another code of choice!!! Background This assignment is based on one of the Big Ideas in this course, namely that reading C source code is a real aid in learning how to write C code. To that end, in this project, you write a program that scans C source from the 'Net and calculates some simple statistics. We're learning lots of concepts, and by running the program you write here on several...
Instructions: For the scenario on the next page, write a paper that explains the following to a prospective client: Formulate both null and alternative hypotheses for the client, and explain why the hypotheses need to be directional or non-directional. Also choose an alpha level (.05 recommended). Determine what statistical test should be used to analyze the data. Summarize all information used to determine the correct statistical test (e.g., number of groups, type of data collected, one or two samples, independent...
Overview: In this course, you will be responsible for completing a number of programming-based assignments by filling in the missing pieces of code. Learning to program in C++ requires developing an understanding of general programming concepts and learning the syntax of the C++ programming language. These exercises will build on each other and help you cultivate you programming knowledge. It is recommended that students do not limit their practice to just that which is graded. The more you write your...
Write a program in the Codio programming environment that allows you to play the game of Rock / Paper / Scissors against the computer. Within the Codio starting project you will find starter code as well as tests to run at each stage. There are three stages to the program, as illustrated below. You must pass the tests at each stage before continuing in to the next stage. We may rerun all tests within Codio before grading your program. Please see...
Please help me write in C++ language for Xcode. Thank you. In this lab you are going to write a time card processor program. Your program will read in a file called salary.txt. This file will include a department name at the top and then a list of names (string) with a set of hours following them. The file I test with could have a different number of employees and a different number of hours. There can be more than...