vendor/topthink/think-helper/tests/ArrTest.php
(开头部分) 2KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
namespace Tests;
use stdClass;
use think\Collection;
use think\helper\Arr;
class ArrTest extends TestCase
{
public function testAdd()
{
$array = Arr::add(['name' => 'ThinkPHP'], 'price', 100);
$this->assertSame(['name' => 'ThinkPHP', 'price' => 100], $array);
}
public function testCrossJoin()
{
// Single dimension
$this->assertSame(
[[1, 'a'], [1, 'b'], [1, 'c']],
Arr::crossJoin([1], ['a', 'b', 'c'])
);
// Square matrix
$this->assertSame(
[[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']],
Arr::crossJoin([1, 2], ['a', 'b'])
);
// Rectangular matrix
$this->assertSame(
[[1, 'a'], [1, 'b'], [1, 'c'], [2, 'a'], [2, 'b'], [2, 'c']],
Arr::crossJoin([1, 2], ['a', 'b', 'c'])
);
// 3D matrix
$this->assertSame(
[
[1, 'a', 'I'], [1, 'a', 'II'], [1, 'a', 'III'],
[1, 'b', 'I'], [1, 'b', 'II'], [1, 'b', 'III'],
[2, 'a', 'I'], [2, 'a', 'II'], [2, 'a', 'III'],
[2, 'b', 'I'], [2, 'b', 'II'], [2, 'b', 'III'],
],
Arr::crossJoin([1, 2], ['a', 'b'], ['I', 'II', 'III'])
);
// With 1 empty dimension
$this->assertSame([], Arr::crossJoin([], ['a', 'b'], ['I', 'II', 'III']));
$this->assertSame([], Arr::crossJoin([1, 2], [], ['I', 'II', 'III']));
$this->assertSame([], Arr::crossJoin([1, 2], ['a', 'b'], []));
// With empty arrays
$this->assertSame([], Arr::crossJoin([], [], []));
$this->assertSame([], Arr::crossJoin([], []));
$this->assertSame([], Arr::crossJoin([]));
// Not really a proper usage, still, test for preserving BC
$this->assertSame([[]], Arr::crossJoin());
}
public function testDivide()
{
list($keys, $values) = Arr::divide(['name' => 'ThinkPHP']);
$this->assertSame(['name'], $keys);
$this->assertSame(['ThinkPHP'], $values);
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。