current

Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Return the current element in an array
Alias pos
<?php current(array|object $array): mixed
<?php         $field = 'answer';



        if (is_array($rules) && ! array_is_list($rules)) {

            [$field, $rules] = [key($rules), current($rules)];

        }



        return $this->getPromptValidatorInstance(
<?php         $this->assertEquals('Post B', $postB->title, 'Expect `Post B` is the result of the second query');



        $this->assertCount(1, $result->items(), 'Expect cursor paginated query should have 1 result');

        $this->assertEquals('Post B', current($result->items())->title, 'Expect the paginated query would return `Post B`');

    }



    public function testPaginationWithMultipleAliases()
<?php         $this->assertSame(['alias'], $result->getOptions()['parameters']);



        $this->assertCount(1, $result->items(), 'Expect cursor paginated query should have 1 result');

        $this->assertEquals('B (post)', current($result->items())->alias, 'Expect the paginated query would return `B (post)`');

    }



    public function testPaginationWithAliasedOrderBy()
<?php         if (count($alterColumnClauses) === 1) {

            $queryParts[] = current($alterColumnClauses);



            return;

        }
<?php     public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)

    {

        $this->output .= $this->createNodeRelation(

            $fkConstraint->getLocalTableName() . ':col' . current($fkConstraint->getLocalColumns()) . ':se',

            $fkConstraint->getForeignTableName() . ':col' . current($fkConstraint->getForeignColumns()) . ':se',

            [

                'dir'       => 'back',
<?php     {

        $this->output .= $this->createNodeRelation(

            $fkConstraint->getLocalTableName() . ':col' . current($fkConstraint->getLocalColumns()) . ':se',

            $fkConstraint->getForeignTableName() . ':col' . current($fkConstraint->getForeignColumns()) . ':se',

            [

                'dir'       => 'back',

                'arrowtail' => 'dot',
<?php         $offset = 0;



        while (($handler = current($patterns)) !== false) {

            if (preg_match('~\G' . key($patterns) . '~s', $sql, $matches, 0, $offset) === 1) {

                $handler($matches[0]);

                reset($patterns);
<?php         $fkConstraints = $fkTable->getForeignKeys();

        self::assertEquals(1, count($fkConstraints), "Table 'test_create_fk1' has to have one foreign key.");



        $fkConstraint = current($fkConstraints);

        self::assertInstanceOf(ForeignKeyConstraint::class, $fkConstraint);

        self::assertEquals('test_foreign', strtolower($fkConstraint->getForeignTableName()));

        self::assertEquals(['foreign_key_test'], array_map('strtolower', $fkConstraint->getColumns()));
<?php         $fks = $table->getForeignKeys();

        self::assertCount(1, $fks);

        $foreignKey = current($fks);

        self::assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName()));

        self::assertEquals(['foreign_key_test'], array_map('strtolower', $foreignKey->getColumns()));

        self::assertEquals(['id'], array_map('strtolower', $foreignKey->getForeignColumns()));
<?php         self::assertTrue($table->hasColumn('rename_fk_id'));

        self::assertCount(1, $foreignKeys);

        self::assertSame(['rename_fk_id'], array_map('strtolower', current($foreignKeys)->getColumns()));

    }



    public function testRenameIndexUsedInForeignKeyConstraint(): void
<?php         self::assertCount(1, $indexes);



        $firstIndex = current($indexes);

        $columns    = $firstIndex->getColumns();

        self::assertCount(2, $columns);

        self::assertEquals('colB', $columns[0]);
<?php         $table->addColumn('long_id', 'integer');

        $table->addIndex(['long_id']);



        $index = current($table->getIndexes());

        self::assertEquals(5, strlen($index->getName()));

    }
<?php         self::assertNotSame($tableB->getColumn('id'), $schemaNew->getTable('bar')->getColumn('id'));



        $fk = $schemaNew->getTable('bar')->getForeignKeys();

        $fk = current($fk);



        $re = new ReflectionProperty($fk, '_localTable');

        $re->setAccessible(true);
<?php         $constraints = $table->getForeignKeys();

        self::assertCount(1, $constraints);

        $constraint = current($constraints);



        self::assertInstanceOf(ForeignKeyConstraint::class, $constraint);
<?php         $indexes = $table->getIndexes();

        self::assertCount(1, $indexes);

        $index = current($indexes);



        self::assertTrue($table->hasIndex($index->getName()));

        self::assertEquals(['id'], $index->getColumns());