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 9024801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T06:06:56+00:00 2026-06-16T06:06:56+00:00

I am processing a CSV authored by a remote system. I don’t want to

  • 0

I am processing a CSV authored by a remote system. I don’t want to assume they won’t change what fields they provide or their order so I am parsing a header row for the indices in the CSV of fields and mapping these into an array I can use for lookups and updates.

Thing is the way I am doing it tests false for index zero:

foreach ($field_map_array as $local_field => $silverpop_field) {
    if ($idx = array_search($silverpop_field, $fields)) {
        $local_to_sp[$local_table][$local_field] = $idx;
    } // index found
}

What’s a better way to do that?

  • 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-16T06:06:57+00:00Added an answer on June 16, 2026 at 6:06 am

    array_search returns an integer if it finds the needle, and FALSE otherwise, so test it explicitly using the !== / not identical operator:

    foreach ($field_map_array as $local_field => $silverpop_field) {
        if (($idx = array_search($silverpop_field, $fields)) !== FALSE) {
            $local_to_sp[$local_table][$local_field] = $idx;
        } // index found
    }
    

    Here’s how the manual describes the difference between != (not equal) and !== (not identical) (emphasis added):

    $a != $b Not equal TRUE if $a is not equal to $b after type juggling.

    $a !== $b Not identical TRUE if $a is not equal to $b, or they are not of the same type.

    The problem with your code is that if(0) is interpreted as if(0 != FALSE). Type juggling lets it cast FALSE to the integer 0, and 0 != 0 is obviously false. With !== type juggling doesn’t occur, so 0 !== FALSE is true (since they’re not the same type).

    I’d recommend using === and !== whenever possible, since they are more predictable, and predictable code tends to be less buggy and easier to work with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm processing a /etc/group file from a system. I load it with CSV input
I am processing some CSV file which i have copied in Bin folder of
Now that I am using it for backend processing of csv files, and the
I need to do some csv file processing in a django app. I heard
I've got a CSV file that I'm processing using the opencsv library. So I
I am processing CSV File Say ABC|06|001 PPP|06|001 I am running LINQ to split
I have a data processing system that generates very large reports on the data
I am a newbie using Java to do some data processing on csv files.
I have some data in CSV format that I want to pull into an
Problem description I want to refactor a parser for a flexible csv like format

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.