Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8548751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:34:02+00:00 2026-06-11T13:34:02+00:00

I am reading from an excel sheet through php code. There some fields are

  • 0

I am reading from an excel sheet through php code. There some fields are optional. when i use the library i get the result like this

Array
    (
    [1] => Test123
    [2] => None
    [3] => Booster
    [6] => Yes
    [7] => Yes
    [8] => 1
    [9] => Unknown
    [10] => 21
    [11] => http://unknowm.com
    )

There you can see index 4 and 5 are missing because the values were not present in the excel file columns. Now i have to merge this array with another array which has named indexes. the length of the second array is 11. But when i merge both a php error is produced saying undefined index 4 and 5. i am doing the work dynamically and i am compelled to use all the indexes of second array. i wnt the first(coming from excel) array indexes which are missing to be filled with empty string before mergin it to the second one. How can i do this? i hope i have provided much information.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T13:34:04+00:00Added an answer on June 11, 2026 at 1:34 pm

    You can use array_fill to create an array with all the keys you want the result to have and use the array addition operator to add those that are missing from the original array:

    $firstIndexToEnsure = 1;
    $lastIndexToEnsure = 11;
    $defaults = array_fill($firstIndexToEnsure,
                           $lastIndexToEnsure - $firstIndexToEnsure + 1,
                           '');
    $array += $defaults;
    

    See it in action.

    If you need the result to be additionally ordered by key then also use ksort on it.

    It’s worthwhile to mention that this technique works very well for non-integer keys too wherever you accept user input that may only partially override some defaults:

    $params = array('color' => 'blue', 'size' => 'large');
    $defaults = array(
        'color' => 'red',
        'size'  => 'large',
        'shape' => 'square',
        'age'   => 'old',
    );
    
    $params += $defaults;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading data from an Excel worksheet. Some of the data is percent
I am reading the excel sheet from C# by using interop services. My sheet
I am using the excel pia's to do some writing and reading to/from excel
Possible Duplicate: Reading Datetime value From Excel sheet I'm trying to read in a
I am reading data from an excel sheet and displaying it in a data
I have this piece of code for reading from an excel cell: public T
I'm having some trouble reading from an Excel spreadsheet in C#. I have this
I'm new to PHP and I am reading data from an excel spreadsheet and
Error while reading Excel sheet from C#: ERROR [IM002] [Microsoft][ODBC Driver Manager] Data source
I need some help on something. I am reading some data from an Excel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.