forked from whcyc2002/swoole_framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.php
More file actions
43 lines (38 loc) · 729 Bytes
/
Copy patharray.php
File metadata and controls
43 lines (38 loc) · 729 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
<?php
define('DEBUG', 'on');
define('WEBPATH', realpath(__DIR__ . '/..'));
//包含框架入口文件
require WEBPATH . '/libs/lib_config.php';
$n = 4;
$array = new \Swoole\ArrayObject();
$array['test1'] = 123;
$array['test2'] = 456;
$array['test3'] = 789;
if ($n == 1)
{
$array->each(function (&$item, $key)
{
var_dump($item, $key);
$item = rand(100, 999);
});
}
elseif ($n == 2)
{
var_dump($array->reverse());
}
elseif ($n == 3)
{
$newArray = $array->map(function ($item)
{
var_dump($item);
return rand(100, 999);
});
var_dump($newArray);
}
elseif ($n == 4)
{
echo $array->reduce(function ($result, $item)
{
return $result + $item;
});
}