本文整理汇总了PHP中Arr::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::insert方法的具体用法?PHP Arr::insert怎么用?PHP Arr::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arr
的用法示例。
在下文中一共展示了Arr::insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_insert
/**
* Tests Arr::insert()
*
* @test
*/
public function test_insert()
{
$people = array("Jack", "Jill");
$expected = array("Humpty", "Jack", "Jill");
$output = Arr::insert($people, "Humpty", 0);
$this->assertEquals(true, $output);
$this->assertEquals($expected, $people);
}
示例2: testInsertsWithStringKeys
public function testInsertsWithStringKeys()
{
$array = ['zero' => 'cat', 'one' => 'dog', 'two' => 'octopus', 'three' => 'raven'];
// inserting before 'dog' which is at index 1
// make 'dog' which was 1, into 2
$result = Arr::insert($array, 'spider', 'one');
// we use `same` here because they must be identical, equals would be true regardless of the order
// UNFORTUNATELY, IT ONLY WORKS FOR NUMERICAL INDEXES
$this->assertSame($result, ['zero' => 'cat', 'one' => 'dog', 'two' => 'octopus', 'three' => 'raven']);
}
示例3: test_insert_with_index_out_of_range
/**
* Tests Arr::insert()
*
* @test
*/
public function test_insert_with_index_out_of_range()
{
$people = array("Jack", "Jill");
$output = Arr::insert($people, "Humpty", 4);
$this->assertFalse($output);
}