Results: 1578
Notes
  • Newest first
  • Oldest first
  • Newest first(All)
  • Oldest first(All)
// Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct.
function containsDuplicate($nums) {
    $nums = array_count_values($nums);
    foreach ($nums as $key => $num) {
	if ($num >= 2) {
	    return true;
	}
    }
    return false;
}
echo containsDuplicate([1, 2, 3, 1]);
by Luka Khitaridze
2 years ago
0
PHP
Array
0
by nikoloz nachkebia
3 years ago
0
PHP
Sum of numbers from 1 to n
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
3 years ago
0
PHP
Array
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
3 years ago
0
PHP
Array
0
by დავით ქუთათელაძე
3 years ago
0
PHP
echo/print
1
by დავით ქუთათელაძე
3 years ago
0
PHP
differences between echo and print
1
Associative array
<?php

$co_members = [
				"name"=>"Oto",
				"weight"=>70,
				"hight"=>180,
				"male"=> true,
				"married"=> true];
				
				echo "$co_members[name] is $co_members[weight]kg and $co_members[hight]cm.";
OUTPUT

Oto is 70kg and 180cm.
by otar datuadze
3 years ago
0
PHP
array
1
by nikoloz nachkebia
3 years ago
0
PHP
Calculates count
sum
product
avg
min and max
0
by nikoloz nachkebia
3 years ago
0
PHP
Swapping two numbers
0
by nikoloz nachkebia
3 years ago
0
PHP
Find the Max of three numbers
0
Results: 1578