How to read CSV data as array pairs in Magento 2?

You can Retrieve CSV file data as pairs by just calling the Magento\Framework\File\Csv class. A Csv.php class contains the getDataPairs() function to convert the first column as a key and the second column as the value in the array from the CSV file.

This article is helpful if you have a CSV file with only two columns and want to treat it as an array key-value pair.

Let’s assume your CSV file contains below value for the first column and a second column with comma-separated,

How to Check file is exists or not at specific location programmatically in Magento 2?

You can check any physical file is exist or not at a specific location in Magento directory by Magento\Framework\Filesystem\Driver\File class.

You can use Magento 2 native class to check file is exist or not instead of the core PHP method.

I have taken a Block file and create a function for check file is exist or not via constructor DI,

Rename a tablename using db_schema(Declarative schema) in Magento 2.

In Magento 2, You can create a new table using db_schema.xml file. After creating a table you want to rename a table name, You can rename a table using declarative schema.

New Table(mycustom_table) db_schema.xml file,

<?xml version="1.0"?>
<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">
    <table name="mycustom_table" onCreate="migrateDataFromAnotherTable(new_declarative_table)">
        <column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true"
                comment="Entity Id"/>
        <column xsi:type="varchar" name="fullname" nullable="true" length="50" comment="Full name"/>
        <column xsi:type="varchar" name="email" nullable="true" length="255" comment="Email"/>
        <column xsi:type="smallint" name="store_id" padding="5" unsigned="true" nullable="true" identity="false"
                default="0" comment="Store Id"/>
    </table>
</schema>

Now you must have to run generate-whitelist command to generate db_schema_whitelist.json file,