本文整理汇总了PHP中CMap::findScalar方法的典型用法代码示例。如果您正苦于以下问题:PHP CMap::findScalar方法的具体用法?PHP CMap::findScalar怎么用?PHP CMap::findScalar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CMap
的用法示例。
在下文中一共展示了CMap::findScalar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findScalar
/**
* Determines if a map contains a specified scalar value.
*
* If a map only contains values of scalar types i.e. `int`, `float`, `bool`, `string` (ASCII only), or `null`,
* this method allows for faster searches compared to `find` method. In case of `string` type, the search is
* case-sensitive.
*
* The `find` method would be of better service in searching for Unicode strings (the default comparator used by
* `find` method is Unicode-aware) and it was made flexible for you to be able to set your own comparison rules,
* such as making the search case-insensitive for any kind of strings.
*
* @param mixed $whatValue The searched value.
* @param reference $foundUnderKey **OPTIONAL. OUTPUT.** If a value has been found after the method was called
* with this parameter provided, the parameter's value is being the first key under which the value was seen. If
* the key is a string, its output type is `CUStringObject`.
*
* @return bool `true` if such value was found in the map, `false` otherwise.
*
* @link #method_find find
*/
public function findScalar($whatValue, &$foundUnderKey = null)
{
$found = CMap::findScalar($this->m_map, $whatValue, $foundUnderKey);
return $found;
}
示例2: testFindScalar
public function testFindScalar()
{
$map = ["one" => "a", "two" => "b", "three" => "c", "four" => "d", "five" => "e"];
$found = CMap::findScalar($map, "c");
$this->assertTrue($found);
$foundUnderKey;
$found = CMap::findScalar($map, "d", $foundUnderKey);
$this->assertTrue($found);
$this->assertTrue($foundUnderKey === "four");
$found = CMap::findScalar($map, "C");
$this->assertFalse($found);
$found = CMap::findScalar($map, "f");
$this->assertFalse($found);
// Special case.
$map = CMap::make();
$found = CMap::findScalar($map, "a");
$this->assertFalse($found);
}