Пример #1
0
 public function testKeyOffset()
 {
     $ary = array(4 => "zero", 2 => "one", 8 => "two", 32 => "three", 16 => "four", 64 => "five");
     $this->assertEquals(0, \r8\ary\keyOffset($ary, 4));
     $this->assertEquals(5, \r8\ary\keyOffset($ary, 64));
     $this->assertEquals(3, \r8\ary\keyOffset($ary, 32));
     try {
         \r8\ary\keyOffset($ary, 65432);
         $this->fail('An expected exception has not been raised.');
     } catch (\r8\Exception\Argument $err) {
         $this->assertSame("Key does not exist", $err->getMessage());
     }
 }
Пример #2
0
/**
 * Returns the offset of the pointer in an array
 *
 * @param Array $array The array to operate on
 * @return Integer|NULL Returns the offset, or NULL if the array is empty
 */
function pointer(array &$array)
{
    if (empty($array)) {
        return NULL;
    }
    return \r8\ary\keyOffset($array, key($array));
}