Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
you will also find that echo is slightly faster than print
by nikoloz nachkebia
3 years ago
0
PHP
Differences between echo and print
1
➤ The for loop is used when you know in advance how many times the script should run.
for (init counter; test counter; increment counter) {
  code to be executed for each iteration;
}
➤ Parameters (divided by ; ): • init counter: Initialize the loop counter value • test counter: Evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends. • increment counter: Increases the loop counter value For instance:
// outputs the numbers from 1 to 10
for ($i = 0; $i <= 10; $i++) {
  echo "The number is: $i \n";
} 

// Without first parameter
$i = 0;
for (; $i <= 10; $i++) {
  echo "The number is: $i \n";
} // outputs the numbers from 1 to 10

// Without first and third parameter
$i = 0;
for (; $i <= 10;) {
  echo "The number is: $i \n";
  $i++; // we got the while loop syntax :))
} // outputs the numbers from 1 to 10

// We can make a for loop infinite without using these three parameters
for ( ; ; ){
	echo "infinite \n";
}
by Levani Makhareishvili
3 years ago
0
PHP
Loops
1
➤ 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.
do {
  code to be executed;
} while (condition is true);
For instance:
$x = 1;
do {
  echo "The number is: $x \n";
  $x++;
} while ($x <= 2);
/* outputs    The number is: 1
              The number is: 2 */
              

$x = 10;
do {
  echo "The number is: $x \n";
  $x++;
} while ($x <= 2);
// outputs   The number is: 10
by Levani Makhareishvili
3 years ago
0
PHP
Loops
1
➤ The while loop executes a block of code as long as the specified condition is true.
while (condition is true) {
   code to be executed;
}
For instance:
// outputs the numbers from 1 to 10
$x = 1;
while($x <= 10) {
  echo "The number is: $x \n";
  $x++;
}

// $x = 1; - Initialize the loop counter ($x), and set the start value to 1
// $x <= 10 - Continue the loop as long as $x is less than or equal to 5
/* $x++; - Increase the loop counter value by 1 for each iteration.
Otherwise, the condition always will be true and the loop will run endlessly*/
by Levani Makhareishvili
3 years ago
0
PHP
Loops
1
➤ Besides the built-in PHP functions, it is possible to create your own functions. • A function is a block of statements that can be used repeatedly in a program. • A function will not execute automatically when a page loads. • A function will be executed by a call to the function. ➤ A user-defined function declaration starts with the word function:
function
functionName() { code to be executed; } functionName() // Calling a function
For instance:
function printMyName() {
	echo "My name is Levani :))\n";
}
printMyName(); // calling a function
➤ Function Arguments Information can be passed to functions through arguments. An argument is just like a variable. Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma. For instance:
// Function with parameters
function printInfo($firstName,$lastName,$age){
	echo "Hello,my name is $firstName $lastName, I am $age years old :))\n";
}
// Arguments
printInfo("Levani","Makhareishvili",19);
$name = "Mads";
$lastName = "Mikkelsen";
$age = 56;
printInfo($name,$lastName,$age);
➤ Note the difference between parameters and arguments: • Function parameters are the names listed in the function's definition. • Function arguments are the real values passed to the function. • Parameters are initialized to the values of the arguments supplied. ➤ The advantages of using functions are: • Functions reduces the repetition of code within a program • Functions makes the code much easier to maintain • Functions makes it easier to eliminate the errors • Functions can be reused in other application
by Levani Makhareishvili
3 years ago
0
PHP
Functions
1
➤ Logical operators are used to combine conditional statements.
Operator     Name	 Example	          Result

  and	      And	$x and $y	True if both $x and $y are true	
  or          Or	$x or $y	True if either $x or $y is true	
  xor	      Xor	$x xor $y	True if either $x or $y is true, but not both	
  &&	      And	$x && $y	True if both $x and $y are true	
  ||	      Or	$x || $y	True if either $x or $y is true	
  !	      Not	!$x	        True if $x is not true
For instance:
$x = 10;
$y = -10;

// Operator - and
if ( $x > 5 and $y > -15 ) {
	echo "True: $x > 5"."\n";
	echo "True: $y > -15"."\n\n";
}

// Operator - or
if ( $x > 100 or $x > -1 ) {
	echo "False: $x > 100"."\n";
	echo "True: $x > -1"."\n\n";
}

// Operator - xor
if ($x == 10 xor $y == -10 ) {
	// both conditional statements are true! 
} else {
	echo "Both is true \n\n";
}

// Operator - && (same as - and)
if ($y <= 0 && $y == -10 and $y != 10) {
	echo "True: $y <= 0\n";
	echo "True: $y = -10\n";
	echo "True: $y != 10\n\n";
}

// Operator - || (same as - or)
if ($x == 1 or $x == 10){
	echo "True: $x = 10\n";
	echo "False: $x = 1\n\n";
}

$x = 0;
// Operator - !
if (!$x) {
	echo "$x is false";
}
➤ The number 0 is considered to be false and all other numbers are considered to be true
by Levani Makhareishvili
3 years ago
0
PHP
Operators
1
The PHP while Loop
The
while
loop executes a block of code as long as the specified condition is true.
$x = 1;
while($x <= 100) {
    echo "The number is $x". "\n";
    $x+=10;
}
by Eka Suarishvili
3 years ago
0
PHP
0
Another example CODE
// Interesting example about if-elseif-else statement

$test = "STRING, NOT INTEGER OR FLOAT";
if ($test < 12) {
	echo "child";
} else if ($test > 12 && $test < 18 ) {
	echo "teen";
} else {
	echo "adult";
}
// what do you think, what will be output, error or ? 
// make that example on your PC if you are a begginer :)
by Luka Khitaridze
3 years ago
1
PHP
PHP LOOPS
-1
by დავით ქუთათელაძე
3 years ago
1
PHP
array types
1
➤ The PHP if-else-if is a special statement used to combine multiple if...else statements. So, we can check multiple conditions using this statement.
if (condition1){    
//code to be executed if condition1 is true    
} elseif (condition2){      
//code to be executed if condition1 is false and condition2 is true
} elseif (condition3){      
//code to be executed if condition2 is false and condition3 is true    
....  
}  else{    
//code to be executed if all given conditions are false    
}
$x = 10;
if ($x > 0) {
	echo "$x is positive\n";
} elseif ($x < 0 ) { // if $x equals negative number
	echo "$x is negative!\n";
} else { // if $x = 0;
	echo "$x is neither positive nor negative \n";
}
by Levani Makhareishvili
3 years ago
0
PHP
else if statement
1
Results: 1578