array_search

Supported Versions: PHP 4 >= 4.0.5, PHP 5, PHP 7, PHP 8
Searches the array for a given value and returns the first corresponding key if successful
<?php array_search(mixed $needle, array $haystack, bool $strict = false): int|string|false
<?php     private function replaceColumn($tableName, array $columns, $columnName, Column $column): array

    {

        $keys  = array_keys($columns);

        $index = array_search(strtolower($columnName), $keys, true);



        if ($index === false) {

            throw SchemaException::columnDoesNotExist($columnName, $tableName);
<?php         $name         = $this->trimQuotes(strtolower($name));

        $indexColumns = array_map('strtolower', $this->getUnquotedColumns());



        return array_search($name, $indexColumns, true) === $pos;

    }
<?php     private function findTypeName(Type $type): ?string

    {

        $name = array_search($type, $this->instances, true);



        if ($name === false) {

            return null;
<?php         $columnsKeys = array_keys($columns);



        self::assertArrayHasKey('id', $columns);

        self::assertEquals(0, array_search('id', $columnsKeys, true));

        self::assertEquals('id', strtolower($columns['id']->getName()));

        self::assertInstanceOf(IntegerType::class, $columns['id']->getType());

        self::assertEquals(false, $columns['id']->getUnsigned());
<?php         self::assertIsArray($columns['id']->getPlatformOptions());



        self::assertArrayHasKey('test', $columns);

        self::assertEquals(1, array_search('test', $columnsKeys, true));

        self::assertEquals('test', strtolower($columns['test']->getname()));

        self::assertInstanceOf(StringType::class, $columns['test']->gettype());

        self::assertEquals(255, $columns['test']->getlength());
<?php         self::assertIsArray($columns['test']->getPlatformOptions());



        self::assertEquals('foo', strtolower($columns['foo']->getname()));

        self::assertEquals(2, array_search('foo', $columnsKeys, true));

        self::assertInstanceOf(TextType::class, $columns['foo']->gettype());

        self::assertEquals(false, $columns['foo']->getunsigned());

        self::assertEquals(false, $columns['foo']->getfixed());
<?php         self::assertIsArray($columns['foo']->getPlatformOptions());



        self::assertEquals('bar', strtolower($columns['bar']->getname()));

        self::assertEquals(3, array_search('bar', $columnsKeys, true));

        self::assertInstanceOf(DecimalType::class, $columns['bar']->gettype());

        self::assertEquals(null, $columns['bar']->getlength());

        self::assertEquals(10, $columns['bar']->getprecision());
<?php         self::assertIsArray($columns['bar']->getPlatformOptions());



        self::assertEquals('baz1', strtolower($columns['baz1']->getname()));

        self::assertEquals(4, array_search('baz1', $columnsKeys, true));

        self::assertInstanceOf(DateTimeType::class, $columns['baz1']->gettype());

        self::assertEquals(true, $columns['baz1']->getnotnull());

        self::assertEquals(null, $columns['baz1']->getdefault());
<?php         self::assertIsArray($columns['baz1']->getPlatformOptions());



        self::assertEquals('baz2', strtolower($columns['baz2']->getname()));

        self::assertEquals(5, array_search('baz2', $columnsKeys, true));

        self::assertContains($columns['baz2']->gettype()->getName(), ['time', 'date', 'datetime']);

        self::assertEquals(true, $columns['baz2']->getnotnull());

        self::assertEquals(null, $columns['baz2']->getdefault());
<?php         self::assertIsArray($columns['baz2']->getPlatformOptions());



        self::assertEquals('baz3', strtolower($columns['baz3']->getname()));

        self::assertEquals(6, array_search('baz3', $columnsKeys, true));

        self::assertContains($columns['baz3']->gettype()->getName(), ['time', 'date', 'datetime']);

        self::assertEquals(true, $columns['baz3']->getnotnull());

        self::assertEquals(null, $columns['baz3']->getdefault());