public function testFindScalar() { $array = CArray::fromElements("a", "b", "c", "d", "e"); $found = CArray::findScalar($array, "c"); $this->assertTrue($found); $foundAtPos; $found = CArray::findScalar($array, "d", $foundAtPos); $this->assertTrue($found); $this->assertTrue($foundAtPos == 3); $found = CArray::findScalar($array, "C"); $this->assertFalse($found); $found = CArray::findScalar($array, "f"); $this->assertFalse($found); // Special case. $array = CArray::make(); $found = CArray::findScalar($array, "a"); $this->assertFalse($found); }
/** * Determines if an array contains an element with a specified scalar value, using linear search. * * If an array 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 $whatElement The value of the searched element. * @param reference $foundAtPos **OPTIONAL. OUTPUT.** If an element has been found after the method was called * with this parameter provided, the parameter's value, which is of type `int`, indicates the position of the first * found element, i.e. the element at the leftmost position if the array contains more than one of such elements. * * @return bool `true` if such element was found in the array, `false` otherwise. * * @link #method_find find */ public function findScalar($whatElement, &$foundAtPos = null) { return CArray::findScalar($this->m_splArray, $whatElement, $foundAtPos); }