-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2603.php
More file actions
47 lines (35 loc) · 938 Bytes
/
2603.php
File metadata and controls
47 lines (35 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
// echo 'hello World';
function basicOp($op, $val1, $val2)
{
$v1 = (int) $val1;
var_dump($v1);
$v2 = (int) $val2;
var_dump($v2);
return eval("return $val1 $op $val2;");
}
echo basicOp('*', 5, 7);
echo '<br>';
function countPositivesSumNegatives($Ary): array
{
if (empty($Ary)) {
return [];
}
$result = array_reduce($Ary, function($carry, $item) {
if ($item > 0) {
$carry[0]++;
} else {
$carry[1] += $item;
}
return $carry;
}, [0, 0]);
return $result;
}
// print_r(countPositivesSumNegatives([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]));
print_r(countPositivesSumNegatives(null));
function countPositivesSumNegatives($Ary): array
{
if (isset
($Ary) && count($Ary) > 0) {
$pos = array_filter(array_map('checkPos', $Ary));
$nag = array_filter(array_map('checkNag', $Ary));