Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
➤ The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.
// This example skips the value of 2
for ($a = 0; $a < 4; $a++) {
  if ($a == 2) {
    continue;
  }
  echo "The number is: $a \n";
} 
/* outputs:  The number is: 0 
	     The number is: 1 
	     The number is: 3
*/


// We print array elements by omitting "Audi".
$cars = array("BMW","Audi","Porsche");
foreach ($cars as $val) {
	if ($val == "Audi") {
		continue;
	}
	echo "$val \n";
}
/* outputs:  BMW
             Porsche
*/
by Levani Makhareishvili
3 years ago
1
PHP
Loops
1
➤ The break statement can be used to jump out of a loop.
// This example jumps out of the loop when a is equal to 5:
for ($a = 0; $a <= 10; $a++) {
  if ($a == 5) {
    break;
  }
  echo "The number is: $a \n";
} 
/* outputs:  The number is: 0 
             The number is: 1
             The number is: 2
             The number is: 3
             The number is: 4
*/


// We print the elements of the array until the value is equal to "Audi".
$cars = array("BMW","Porsche","Audi","Mercedes-Benz");
foreach ($cars as $val) {
	if ($val == "Audi") {
		break;
	}
	echo "$val \n";
}
/* outputs:  BMW
             Porsche
*/
by Levani Makhareishvili
3 years ago
0
PHP
Loops
1
➤ The foreach loop works only on arrays, and is used to loop through each key/value pair in an array.
foreach ($array as $value) {
  code to be executed;
}
For instance:
// array - $country
$country = ["Georia","Ukraine","Spain"];

foreach ($country as $value) { // Instead of name $value we can write any name
  echo "$value \n";
}
/* outputs:    Georia 
	       Ukraine 
               Spain 
 */
 
 // array - numbers
 $numbers = array("one" => 1 , "two" => 2 , "three" => 3 );

foreach($numbers as $n => $value) {
  echo "$n = $value \n";
}
/*outputs:   one = 1
             two = 2
             three = 3
*/
// also, we can print only keys/values
foreach($numbers as $n => $value){
	echo "$n \n"; // if we need value of key, we must whrite $value
}                 // keys are "one","two","three" and values are 1,2,3
/*outputs:   one
	     two
	     three
*/
by Levani Makhareishvili
3 years ago
0
PHP
Loops
1
by დავით ქუთათელაძე
3 years ago
0
PHP
if statement
1
by დავით ქუთათელაძე
3 years ago
0
PHP
math functions
1
The code will return an array with 2 elements.
$str = "Hello world";
print_r (explode(" ",$str));
Return:
Array ( [0] => Hello [1] => world )
The code will return a string containing the elements of the array.
$arr = array('Hello','World!');
echo implode(" ",$arr);
Return:
Hello World!
by saba chankvetadze
3 years ago
0
PHP
PHP official doc
0
პროგრამა ბეჭდავს რიცხვებს 1-50, ხუთს-ხუთს თითო ხაზზე
<?php  
for ($i=1;$i<=50;$i++)  {
    echo "$i ";
      if ($i%5==0) {
       echo "\n";
    }
    
}
?>
by Guram Azarashvili
3 years ago
3
PHP
0
small program
// პროგრამა დააბრუნებს წლის დღეს (ციფრს) შესაბამისი გრამატიკული ფორმატით //(date'z') ფუნქცია აბრუნებს წლის მიმდინარე რაოდენობრივ დღეს 1-დან 365-ის ჩათვლით
<?php
$today =(date'z');  
if ($today==1) {
    echo "დღეს არის წლის $today-ლი დღე";
}
elseif ($today>=2 and $today<=20) {
    echo "დღეს არის წლის მე-$today დღე";
}else
echo "დღეს არის წლის $today-ე დღე";
?>
by Guram Azarashvili
3 years ago
0
PHP
PHP official doc
0
by nikoloz nachkebia
3 years ago
0
PHP
Array types
1
For, While Loops CODE
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;
}

The PHP while Loop

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;
}
`
by Gigi Butchvelashvili
3 years ago
1
PHP
-1
Results: 1578