Excel To PHP Array

Login

Email
Password

Don't have an account yet?

Go to Sign up

{{ workbook ? 'Online Table Editor' : 'Input Data' }}
Change File Enter Data
Row Col Row Col
Transpose Clear Delete Empty Deduplicate
ABC abc Abc
Replace
First Row as Header
{{ displayRows.length }} rows x {{ displayHeaders.length }} columns{{ firstRowAsHeader ? ' (1 header)' : '' }} {{ selectedRows.length > 0 ? selectedRows.length + ' selected' : '' }}
Output Data
{{ copied ? 'Copied!' : 'Copy to Clipboard' }} Download File
Properties
Convert Excel to PHP online — paste, edit, and download PHP.

Convert Restart
Insert Row Below
Insert Row Above
Insert Column Right
Insert Column Left
Delete Row {{ contextMenu.row + 1 }}
Delete Column {{ contextMenu.col + 1 }}
Clear Cell
Clear Row
Case sensitive Use regex Cancel Replace All

What Is a PHP Array?

A PHP array is an ordered map that associates keys with values. PHP supports three array types: indexed (auto-assigned numeric keys), associative (named string keys), and multidimensional (arrays containing other arrays). Arrays are the most versatile data structure in PHP — used for configuration, form handling, database results, and data interchange.

Converting Excel data to a PHP array produces a ready-to-paste code block you can drop into Laravel seeders, configuration files, WordPress plugins, PHPUnit data providers, or any PHP script that needs tabular data.

PHP Array Syntax at a Glance

TypeShort Syntax []Legacy Syntax array()
Indexed["Alice", "Bob", "Carol"]array("Alice", "Bob", "Carol")
Associative["name" => "Alice"]array("name" => "Alice")
Multidimensional[["Alice", 30], ["Bob", 25]]array(array("Alice", 30))
Mixed keys[0 => "a", "name" => "b"]array(0 => "a", "name" => "b")

Why Convert Excel to PHP Arrays?

  • Laravel seeders — Paste converted arrays directly into database/seeders/ files to populate tables with initial or test data.

  • PHPUnit data providers — Generate array datasets from spreadsheet test cases for parameterized tests.

  • Configuration files — Store lookup tables, status codes, or country lists as PHP config arrays that return data directly.

  • WordPress plugins — Define option lists, shortcode attributes, or metabox configurations from spreadsheet-based specs.

  • Data migration — Move spreadsheet data into PHP-based systems without intermediate CSV parsing or database imports.

  • Rapid prototyping — Convert product catalogs, pricing tiers, or geographic data into arrays you can iterate over immediately.

Core Features

  • Drag-and-drop upload — Drop any .xlsx, .xls, or .xlsm file onto the upload zone.

  • Built-in table editor — Modify cell values, add or delete rows and columns, transpose, deduplicate, and apply case transformations before conversion.

  • Multi-sheet support — Switch between worksheets in multi-sheet workbooks via the sheet selector dropdown.

  • First Row as Header toggle — Control whether the first row is treated as column headers (producing associative arrays) or regular data (producing indexed arrays).

  • Find & Replace — Bulk-replace cell values with optional regex and case-sensitive matching.

  • Undo / Redo — Full edit history so you can revert mistakes.

  • Copy to clipboard — One-click copy of the generated PHP array code.

  • 100% client-side — Your spreadsheet data never leaves your device. No files are uploaded to any server.

How to Convert Excel to PHP Array

  1. Upload your file — Drag an .xlsx, .xls, or .xlsm file onto the upload area, or click Click here to choose to browse.

  2. Edit if needed — Use the built-in table editor to modify values, add or remove rows and columns, transpose, deduplicate, or apply case changes.

  3. Set options — Toggle First Row as Header on for associative array output (column names as keys) or off for indexed array output (numeric keys).

  4. Click Convert — Press the Convert button in the Properties panel. The PHP array output appears in the Output Data area.

  5. Copy the result — Click Copy to Clipboard and paste the PHP code into your project.

Output Example

Input spreadsheet (employees.xlsx):

NameDepartmentSalary
AliceEngineering95000
BobMarketing72000
CarolEngineering102000

Generated PHP array output (First Row as Header OFF — indexed):

[
   ["Name", "Department", "Salary"],
   ["Alice", "Engineering", "95000"],
   ["Bob", "Marketing", "72000"],
   ["Carol", "Engineering", "102000"]
]

Generated PHP array output (First Row as Header ON — associative):

[
   ["Name" => "Alice", "Department" => "Engineering", "Salary" => "95000"],
   ["Name" => "Bob", "Department" => "Marketing", "Salary" => "72000"],
   ["Name" => "Carol", "Department" => "Engineering", "Salary" => "102000"]
]

Using the Output in a Laravel Seeder

<?php
   namespace DatabaseSeeders;
   use IlluminateDatabaseSeeder;
   use AppModelsEmployee;

   class EmployeeSeeder extends Seeder{
   public function run()
   {
       $employees = [
           ["Name" => "Alice", "Department" => "Engineering", "Salary" => "95000"],
           ["Name" => "Bob", "Department" => "Marketing", "Salary" => "72000"],
           ["Name" => "Carol", "Department" => "Engineering", "Salary" => "102000"],
       ];
       foreach ($employees as $row) {
           Employee::create([
               'name'       => $row['Name'],
               'department' => $row['Department'],
               'salary'     => (int) $row['Salary'],
           ]);
       }
   }
}

Indexed vs Associative PHP Arrays for Tabular Data

AspectIndexed (Numeric Keys)Associative (String Keys)
Access pattern$row[0], $row[1]$row["Name"]
ReadabilityLower — must remember column orderHigher — self-documenting keys
MemoryCompactSlightly larger (key storage)
Column reorder safetyBreaks if columns moveSafe — keyed by name
Best forMatrices, coordinate data, simple listsSeeders, configs, API payloads

Use the First Row as Header toggle to switch between indexed and associative output.

PHP Array Functions Quick Reference

FunctionDescriptionExample
count()Number of elementscount($data) // 3
array_column()Extract a single columnarray_column($data, "Name")
array_map()Transform each elementarray_map(fn($r) => $r["Salary"], $data)
array_filter()Filter by conditionarray_filter($data, fn($r) => $r["Department"] === "Engineering")
array_push()Append an elementarray_push($data, ["Name" => "Dave"])
foreachIterate over elementsforeach ($data as $row) { ... }

Frequently Asked Questions

  • What file formats does this tool accept?

    The tool accepts Microsoft Excel files in .xlsx, .xls, and .xlsm formats. LibreOffice and Google Sheets files exported as .xlsx also work.

  • Does the tool upload my Excel file to a server?

    No. All processing happens entirely in your browser using client-side JavaScript. Your file never leaves your device. There are no server uploads, transfers, or storage of any kind.

  • What PHP array syntax does the tool generate?

    The tool generates the short array syntax [] introduced in PHP 5.4, which is the modern standard. All modern PHP frameworks (Laravel, Symfony, WordPress) support this syntax.

  • What is the difference between indexed and associative output?

    With First Row as Header disabled, each row becomes a numeric-keyed array — accessed by position ($row[0]). With it enabled, each row becomes an associative array — accessed by column name ($row["Name"]). Associative arrays are more readable and preferred for seeders, configs, and API payloads.

  • Can I edit the data before converting to a PHP array?

    Yes. After uploading, a full table editor appears. You can modify individual cells, add or delete rows and columns, transpose the table, remove duplicates, apply case transformations (UPPERCASE, lowercase, Capitalize), and perform find-and-replace operations.

  • Does the tool support multi-sheet Excel files?

    Yes. When your workbook contains multiple sheets, a dropdown selector appears in the editor header. Choose the sheet you want to convert.

  • Can I convert numeric cells to PHP integers or floats?

    The converter outputs all cell values as strings to preserve fidelity. In your PHP code, cast types as needed: (int) $row["Salary"] or (float) $row["Price"].

  • Is there a file size limit?

    Since processing is entirely client-side, the limit depends on your browser's memory. Most modern browsers handle workbooks with tens of thousands of rows without issues.

Featured Tools

Featured tools that you might find useful.

Popular Tools

List of popular tools that users love and frequently use.

New Tools

The latest tools added to our collection, designed for you.

Topics

The tools grouped by topics to quickly find what you need.
Free online Excel to INI file converter. Upload your .xlsx or .xls file and generate INI configuration files with custom sections, key-value separators, and comment styles. No data leaves your browser.

Excel To INI

Free online Excel to INI file converter. Upload your .xlsx or .xls file and generate INI configuration files with custom sections, key-value separators, and comment styles. No data leaves your browser.
Free online Excel to JSONLines converter. Upload your .xlsx or .xls file and convert each row to a JSON object or array in JSON Lines format. Client-side processing — no data leaves your browser.

Excel To JSONLines

Free online Excel to JSONLines converter. Upload your .xlsx or .xls file and convert each row to a JSON object or array in JSON Lines format. Client-side processing — no data leaves your browser.
Free online Excel to LaTeX table converter. Upload your .xlsx or .xls file, customize table formatting options, and generate publication-ready LaTeX code instantly. No data leaves your browser.

Excel To LaTeX Table

Free online Excel to LaTeX table converter. Upload your .xlsx or .xls file, customize table formatting options, and generate publication-ready LaTeX code instantly. No data leaves your browser.
Free online Excel to Custom Template converter. Upload your Excel file and instantly transform it into any custom format using flexible templates with magic syntax. No data leaves your device.

Excel To Custom Template

Free online Excel to Custom Template converter. Upload your Excel file and instantly transform it into any custom format using flexible templates with magic syntax. No data leaves your device.