This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Дано два числа. Вывести наибольшее из них | |
<?php | |
$a = 100; | |
$b = 50; | |
if ($a > $b){ | |
echo $a; | |
} | |
elseif ($b > $a) | |
echo $b; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Напишите функцию PHP для фильтрации многомерного массива. Функция вернет те элементы, которые будут соответствовать указанному значению | |
<?php | |
function array_filter_by_value($my_array, $index, $value) | |
{ | |
if(is_array($my_array) && count($my_array)>0) | |
{ | |
foreach(array_keys($my_array) as $key){ | |
$temp[$key] = $my_array[$key][$index]; | |
if ($temp[$key] == $value){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Напишите программу PHP, чтобы получить расширение файла | |
<?php | |
function file_extension($str1){ | |
$str1=implode("",explode("\\",$str1)); | |
$str1=explode(".",$str1); | |
$str1=strtolower(end($str1)); | |
return $str1; | |
} | |
$file='example.txt'; | |
echo "\n".file_extension($file)."\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Напишите программу PHP, чтобы получить все значения для данного ключа. | |
<?php | |
function pluck($items, $key) | |
{ | |
return array_map( function($item) use ($key) { | |
return is_object($item) ? $item->$key : $item[$key]; | |
}, $items); | |
} | |
print_r(pluck([ | |
['product_id' => 'p100', 'name' => 'Компьютер'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Спросите у пользователя с помощью мультиселекта, какие из языков он знает: html, css, php, javascript. Выведите на экран те языки, которые знает пользователь. | |
<?php | |
if (isset($_REQUEST['lang'])) { | |
echo 'Вы знаете: ' .implode(', ', $_REQUEST['lang']); | |
} | |
?> | |
<form action="" method="get"> | |
<select name="lang[]" multiple id=""> | |
<option value="html">html</option> | |
<option value="css">css</option> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Напишите PHP-скрипт для создания двумерного массива (4х4), инициализированного до 10. | |
<?php | |
$a = array_fill(0, 4, array_fill(0, 4, 10)); | |
echo "<pre>"; print_r($a); echo "</pre>"; | |
?> | |
//Напишите PHP-скрипт для генерации простого случайного пароля [не используйте функцию rand ()] из заданной строки. | |
<?php | |
function password_generate($chars) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Напишите скрипт PHP, чтобы получить самый большой ключ в массиве. | |
<?php | |
$ceu = array( "Italy"=>"Rome", "Luxembourg"=>"Luxembourg", "Belgium"=> "Brussels", | |
"Denmark"=>"Copenhagen", "Finland"=>"Helsinki", "France" => "Paris", "Slovakia"=>"Bratislava", | |
"Slovenia"=>"Ljubljana", "Germany" => "Berlin", "Greece" => "Athens", "Ireland"=>"Dublin", | |
"Netherlands"=>"Amsterdam", "Portugal"=>"Lisbon", "Spain"=>"Madrid", "Sweden"=>"Stockholm", | |
"United Kingdom"=>"London", "Cyprus"=>"Nicosia", "Lithuania"=>"Vilnius", "Czech Republic"=>"Prague", "Estonia"=>"Tallin", "Hungary"=>"Budapest", "Latvia"=>"Riga", "Malta"=> "Valetta","Austria" => "Vienna", "Poland"=>"Warsaw") ; | |
$max_key = max( array_keys( $ceu) ); | |
echo $max_key."\n"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Задания этого типа удобнее проверять здесь: https://www.onlinegdb.com/online_php_interpreter | |
//На вход подается строка из чисел, разделенных пробелами. Найдите максимальное произведение двух чисел из этой строки. | |
<?php | |
$line = trim(fgets(STDIN)); | |
$nums = explode(' ', $line); | |
$max = $nums[0] * $nums[1]; | |
foreach($nums as $i => $num1) { | |
foreach($nums as $j => $num2) { | |
if ($i === $j) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Выведите строку "x больше y" если переменная $x > $y. | |
<?php | |
$x = 50; | |
$y = 10; | |
if ($x>$y) | |
{ | |
echo "x больше y"; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*Напишите функцию PHP для округления числа с плавающей запятой от нуля до указанного числа десятичных знаков. | |
Примеры чисел: | |
(52.78001, 2) | |
(9.131001, 2) | |
(0.786001, 4) | |
(-.125481, 3) | |
-.125481 | |
*/ | |
<?php |
NewerOlder