as i was creating new module in magento2 which has table so when i was going through existing modules i found this function

$indexes= array();

we are just creating array ok fine.

but if you go further you find this function

foreach($indexes AS $index)

i did not get what exactly going through and why we are using this $indexes array.

1 Answer 1


Well, I'm not totally sure what you're asking exactly.

Basically the array you're describing is an array of database indexes.

In your case, it's empty but it usually contains a list of table columns that will be used for database index.

Here's a very simple example for the cms_block_store table:

        $installer->getIdxName('cms_block_store', ['store_id']),

The first parameter generates an unique index name:

$installer->getIdxName('cms_block_store', ['store_id'])

The second parameter is an array of columns that will be used for the index.


There can also be a third parameter for option such as the index type:

['type' => AdapterInterface::INDEX_TYPE_FULLTEXT]

The details of the addIndex method can be found under Magento/Framework/DB/Ddl/Table.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.