本文整理匯總了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);
}