本文整理汇总了PHP中Arr::previous_by_key方法的典型用法代码示例。如果您正苦于以下问题:PHP Arr::previous_by_key方法的具体用法?PHP Arr::previous_by_key怎么用?PHP Arr::previous_by_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arr
的用法示例。
在下文中一共展示了Arr::previous_by_key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_previous_by_key
/**
* Tests Arr::previous_by_key()
*
* @test
*/
public function test_previous_by_key()
{
// our test array
$arr = array(2 => 'A', 4 => 'B', 6 => 'C');
// test: key not found in array
$expected = false;
$test = \Arr::previous_by_key($arr, 1);
$this->assertTrue($expected === $test);
// test: no previous key
$expected = null;
$test = \Arr::previous_by_key($arr, 2);
$this->assertTrue($expected === $test);
// test: strict key comparison
$expected = false;
$test = \Arr::previous_by_key($arr, '2', false, true);
$this->assertTrue($expected === $test);
// test: get previous key
$expected = 2;
$test = \Arr::previous_by_key($arr, 4);
$this->assertTrue($expected === $test);
// test: get previous value
$expected = 'A';
$test = \Arr::previous_by_key($arr, 4, true);
$this->assertTrue($expected === $test);
}
示例2: convert_img_size_down
public static function convert_img_size_down($size, $type = 'm')
{
$size = strtoupper($size);
$sizes = conf('upload.types.img.types.' . $type . '.sizes');
if (!array_key_exists($size, $sizes)) {
return false;
}
return Arr::previous_by_key($sizes, $size);
}