/** * 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; }
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); }