Subscribe
Duration : 1 Year
Author : Web Development Tutorials
Price : $50
Tecwallet Funds available: $0
LogIn Forgot password? Create account
OR
for (var i = 1; i < 11; i = i + 1)
{
console.log(i);
}
In this video, we are demonstarting how to install XAMPP for PHP, My SQL and PHP.
XAMPP is a free and open source web server solution consisting Apache HTTP Server, MySQL database, and interpreters for scripts written in the PHP and Perl programming languages.
echo "Hello PHP!";
echo “Hello, the age is ” . $myAge
Lets try it out…
<?php
echo (29 * 500) + (36 * 19) - 20000;
?>
Lets try it out…
$myName = “Deep Sukhwani”;
$myAge = 25;
List of comparison operators:
Eg:
if ( $userAge > 16 )
{
echo “You can drive!”;
}
Optionally you can also have else statements, these will execute when the condition fails to fulfill (i.e. if the answer to the condition is no.)
Eg (contd. from above):
else
{
echo “Sorry, you can’t drive!”;
}
switch (2) {
case 0:
echo 'The value is 0';
break;
case 1:
echo 'The value is 1';
break;
case 2:
echo 'The value is 2';
break;
default:
echo "The value isn't 0, 1 or 2";
switch (variable)
{
}
switch ($i):
endswitch;
$names = array(”Deep", ”Raj", ”Kunal" );
You can add any type of information to an array, and you do it in much the same way as when declaring variables. Use "" when adding strings, and just enter the number when adding integers. Each item in an array must be separated by a comma:
$names = array(“Deep”, “Raj”, “Kunal”);
The first item “Deep” in above array is numbered 0
Second item “Raj” is numbered 1 and so on…
Therefore, we can access a particular item of the array using its position, like this:
echo $names[1]
//outputs “Raj”
$names = array(“Deep”, “Raj”, “Kunal”);
echo $names[1];
//outputs “Raj”
$names[1] = “Tania”;
echo $names[1];
//outputs “Tania”
Eg:
$languages = array(“JavaScript”, “Python”, “PHP”);
unset($languages [2]);
You can even delete the whole array:
unset($languages);
for ($i = 0; $i < 10; $i++)
{
echo $i;
}
So the above example says: "Start looping with $i at 0, stop the loop before $i gets to 10, count up by 1 each time, and for each iteration, echo the current value of $i."
($i++ is the shorthand for $i = $i + 1.)
while (condition)
{
//Code to execute as long as the condition is true..
//some logic to turn condition to false
//the logic to turn condition false is necessary else
//the loop will execute forever (infinite loop)…
}
while (condition)
{
//Code to execute as long as the condition is true..
//some logic to turn condition to false
//the logic to turn condition false is necessary else
//the loop will execute forever (infinite loop)…
}
<?php
// get the length of a string and
// print it to the screen
$length = strlen(”Deep Sukhwani");
print $length;
?>
$myname = “Deep”
$partial = substr($myname, 0, 3);
print $partial
// prints “dee”
Note: the second parameter (the starting character) is based on a zero-indexed array (i.e. the first character in your string is number 0, not number 1)
Lets see some more useful string functions like strtoupper() and strtolower(), which makes your entire string UPPERCASE or lowercase.
strpos(“deep”, “p”); //3
strpos(“tecwallet”, “tec”); //0
The parameter passed to the strpos() function as like haystack and needle. The function tries to find the needle in the haystack.
It returns either the index of the first character or false if the “needle” cannot be found.
Eg:
if (strpos(“deep”, “a”) == false)
{
print “Sorry no ‘a’ in ‘deep’”;
}
Lets try this example…
$round = round(M_PI);
print $round; //prints 3
Lets round pi to 4 decimal places
$round_decimal = round(M_PI, 4);
print $round_decimal;
Note: M_PI is a PHP constant that is equal to the value of pi
$names = array();
array_push($names, “Deep”);
array_push($names, “TecWallet”);
array_push($names, “Abhishek”);
array_push($names, “Paras”);
print count($names); // prints 4
$array = array(5, 3, 7, 1);
sort($array);
print join(", ", $array);
Eg:
$array = array(5, 3, 7 ,1);
rsort($array);
print join(":", $array);
// prints "7:5:3:1”
Comments ( To Post Your Comment Please Login First! )