Results: 1580
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
// 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
2 years ago
0
PHP
Array
0
<?php # variable echo " QUESTIONNAIRE :"; $giusha = "giusha"; $asaki = 24; $wona = 68.2; $simagle = 1.8; echo "\nMy name $giusha 🙋️"; echo "\nMy age" ."$asaki 🔥"; echo "\nMy weight $wona 🏋️ "; print "\nMy height $simagle 🧍"; print "\n\n MY LOVING BREND :"; # array $brends = [ "Name"=>"BMW", "Name1"=>"MERCEDEC", "Name2"=> "toyota", ]; $brends ["no person"] = [true]; print_r ($brends); echo 'My lovd is :'. $brends ['Name1'] ."\n"; echo "\n When you born?"; $born = 1998; echo "\n\ni was born $born : 3 june"; ?>
by giorgi modebadze
2 years ago
0
PHP
#array
#array types
#string
0
Indexed array ptint_r var_dump
<?php

$colors = ["Red", 7735, "Blue"];
$colors[] = "Yellow";  //add new member in last position


echo $colors[0]; 

echo "\n\n\n";

print_r($colors);

echo "\n\n\n";

var_dump($colors);
OUTPUT:
Red


Array
(
    [0] => Red
    [1] => 7735
    [2] => Blue
    [3] => Yellow
)



array(4) {
  [0]=>
  string(3) "Red"
  [1]=>
  int(7735)
  [2]=>
  string(4) "Blue"
  [3]=>
  string(6) "Yellow"
}
by otar datuadze
2 years ago
0
PHP
0
by nikoloz nachkebia
2 years ago
0
PHP
Finds the Max of two numbers
0
by nikoloz nachkebia
2 years ago
0
PHP
Find the Max of three numbers
0
by nikoloz nachkebia
2 years ago
0
PHP
Swapping two numbers
0
by nikoloz nachkebia
2 years ago
0
PHP
Calculates count
sum
product
avg
min and max
0
// Given an array nums of size n, return the majority element. // The majority element is the element that appears more than ⌊n / 2⌋ times. // Example 1: Input: nums = [3,2,3], Output: 3
function majorityElement($nums) {
    $quantity = count($nums);
    $nums = array_count_values($nums);
    foreach($nums as $key => $num) {
        // two values can't be more than 50% of array
	if ($num > $quantity / 2) {
	    return $key;
	}
    }
}
echo majorityElement([0, 1, 1, 3, 4, 1, 1]);   //1
echo majorityElement([2, 2 ,1 ,1 ,1 ,2 ,2]);   //2
by Luka Khitaridze
2 years ago
0
PHP
Array
0
// Given a sorted array of distinct integers and a target value, return the index if the target is found. // If not, return the index where it would be if it were inserted in order.
function searchInsert($nums, $target) {
    if (in_array($target, $nums)) {
        $index = array_search($target, $nums);
	return $index;
    }
    if (!in_array($target, $nums)) {
        array_push($nums, $target);
	sort($nums);
	$index2 = array_search($target, $nums);
	return $index2;
    }
}
echo searchInsert([1, 3, 5, 6], 5);  // 2
echo searchInsert([1, 3, 5, 6], 2);  // 1
by Luka Khitaridze
2 years ago
0
PHP
Array
0
by nikoloz nachkebia
2 years ago
0
PHP
Sum of numbers from 1 to n
0
Results: 1580