Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
More about array indexes CODE
It's possible to define keys only for some of the array items
$array = [1, 2, "name"=>"Three", 4];
print_r($array);
Result
Array
(
    [0] => 1
    [1] => 2
    [name] => Three
    [2] => 4
)
If we set higher index manually, it will continue adding 1 to the max index
$array = [1, 2, 7=>"Three", 4];
print_r($array);
Result
Array
(
    [0] => 1
    [1] => 2
    [7] => Three
    [8] => 4
)
If we set higher index manually, it will continue adding 1 to the index
$array = [1, 2, 7=>"Three", 4=>"forth", 25];
print_r($array);
Result
Array
(
    [0] => 1
    [1] => 2
    [7] => Three
    [4] => forth
    [8] => 25
)
Only integer and string values are allowed as array keys
$array = [
	1    => "a",
    "1"  => "b",
    "-1"  => "-b",
    '1.5'  => "c",
    true => "d",
];
print_r($array);
Result
Array
(
    [1] => d
    [-1] => -b
    [1.5] => c
)
by Valeri Tandilashvili
3 years ago
2
PHP
Arrays
0
array_push and print_r functions with arrays.
`
$items = array("me", "you", "he");

array_push($items, "she", "we");

print_r($items);
`
by Gigi Butchvelashvili
3 years ago
0
PHP
array
0
Date and Time CODE
`
Formats can be:

echo "Today is ". date("Y/m/d") . "\n";
echo "Today is ". date("d/m/Y"). "\n";
echo "Today is ". date("D/M/Y"). "\n";
echo "Today is ". date("d/M/Y"). "\n";
echo "Today is ". date("d.m.Y"). "\n";
echo "Today is ". date("d-m-Y"). "\n";
echo "Today is ". date("l"). "\n";
`
`
Output:
Today is 2022/10/22
Today is 22/10/2022
Today is Sat/Oct/2022
Today is 22/Oct/2022
Today is 22.10.2022
Today is 22-10-2022
Today is Saturday
`
by Gigi Butchvelashvili
3 years ago
0
PHP
0
by nikoloz nachkebia
3 years ago
0
PHP
"continue" Statement
0
by დავით ქუთათელაძე
3 years ago
0
PHP
logical operators
0
Variable types
string
$name = 'oto' ;
integer
$age = 32;
float
$height= 1.8;
booleean
$android = true;
array
$fruits = [apple , watermelon , orange ];
by otar datuadze
3 years ago
0
PHP
variable types
0
sum of number 1 to n
<?php

$x = 10;

// Sum of numbers from 1 to n
$sum = 0;
for ($i = 1;  $i <= $x;  $i++) {
	$sum += $i;
}
echo "SUM of numbers from 1 to $x: $sum\n";


// easy way to calculate SUM of numbers to n
$sum = $from1To * ($x+1) / 2;
echo "SUM of numbers from 1 to $x: $sum\n";
by Gvanca Gharibashvili
3 years ago
0
PHP
Object Oriented PHP Tutorial
0
some string functions
ფინქცია დააბრუნებს გარკვეულ ინფოს გადაცემულ ტექსტზე:
function str_info($string,$pos){
    $arr= ["length is: ". strlen($string),
           "UPPER:". strtoupper($string),
           "string possitin: " .strpos($string, $pos),
           "reverse is: ".strrev($string)];
    return implode("\n", $arr) ; // აქ შეაერთებს მასივის ელემენტებს და დააბრუნებს ტექსტის სახით
შედეგი length is: 13 UPPER:YOU ARE GREAT string possitin: 4 reverse is: taerg era uoY
by Guram Azarashvili
3 years ago
0
PHP
functions
0
Array random numbers
მასივში ჩაწერს მითითებული დიაპაზონის (0-100) შემთხვევითად გენერირებულ რიცხვებს:
<?php
$arr=[];
for ($i=0; $i<10; $i++){
    $arr[$i]= rand(0,100);  
}
print_r($arr);
by Guram Azarashvili
3 years ago
0
PHP
Array
0
// Manipulate on the two arrays with the same values both in PHP and JS.
// in PHP 
$array = [0, 1, 2];
$array2 = $array;
$array2[1] = 6;
array_push($array2, 3);
print_r ($array);
print_r($array2);
// $array = [0, 1, 2],    $array2 = [0, 6, 2, 3]
// In JS
let array = [0, 1, 2];
let array2 = array;
array2[1] = 6;
array2.push(3);
console.log(array);
console.log(array2);
// array = array2 = [0, 6, 2, 3]
// in JS It's the same array (since it's an object, it's the same reference), you need to create a copy to manipulate them separately // using slice() (or spread operator) in JS (which creates a new array with the elements at the first level copied over), like this:
let a = [0, 1, 2];
let b = a.slice();
b.push(3);
b[1] = 6;
console.log(a, b);
// and the result of 1st and 2nd arrays will not be same. like it wasn't in PHP
// P.s at that case will not change anything, because it's not reference already,
// we just took array's element, the primitive type (integer), not object or array.
let array = [0, 1, 2];
let value = array[1];
value = 10;
console.log(array);  // [0, 1, 2], will not change
console.log(value);    // 10
// but if there will be object, or array as an element in array and if we will modify on it, 
// than the main array will change the value as well.
const array = [{name: 'lela'}, {name: 'gela'}, {name: 'bela'}];
const object = array[0];
object.name = 'test';
console.log(array);
console.log(object);
by Luka Khitaridze
3 years ago
0
PHP
Array
0
Results: 1578