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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:28:13+00:00 2026-05-12T05:28:13+00:00

of all the languages i know im the weakest in php… I have a

  • 0

of all the languages i know im the weakest in php…

I have a script… that takes a csv file and does some stuff with it… fairly simple.

the issue i am having:
in_array(‘username’, $headers) … returns null…
while…
print_r ($headers); shows username being the first entry in the csv.

thoughts? mistakes i may have made?

TIA

code here

/// Turn the string into an array
            $rows = explode("\n", $this->raw_data);

            /// First row includes headers
            $headers = $rows[0];
            $headers = explode($this->delimiter, $headers);

            /// Trim spaces from $headers
            $headers = array_map('trim', $headers);

            /// Check that there are no empty headers. This can happen if there are delimiters at the end of the file
            foreach($headers as $header){

                    if(!empty($header)){
                            $headers2[] = $header;
                    }
            }
            $headers = $headers2;

            if(! in_array('password', $headers)){
                    /// Add password column for generated passwords
                    $headers[] = 'password';
            }
            /// Add status column to the headers
            $headers[] = 'status';

            $this->headers = $headers;

            /// Check that at least username, name and email are provided in the headers
            if(!in_array('username', $headers) ||
               !in_array('name', $headers) ||
               !in_array('email', $headers)){

               echo "error\n";   
               return false;
            }
  • 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-05-12T05:28:13+00:00Added an answer on May 12, 2026 at 5:28 am

    You can use the built in str_getcsv() function. Try replacing the $headers variable assignment with

    $headers = str_getcsv($rows[0], $this->delimiter);
    

    Then find the value(column) you want and loop through the rest of the $rows using the same str_getcsv() function to get the matches you need.

    You may want to use the file() function to grab the file in an array delimited by newlines to begin with, as well.

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

Sidebar

Related Questions

I know some higher level languages, all web based (PHP, javascript, some python). I've
For instance, I know that basically all languages that are object oriented based are
I know in most, if not all programming languages, integers, floats etc all have
Nearly all programming languages that support threading, have a method called join . I
In all of the standard specifications for programming languages, why is it that you
In all the languages that I understand this is not possible but someone was
I am seeing all these new languages for .NET and JVM. How does one
What are all the computer languages that exist, and how many people use them?
I know this is going to not be the same across all languages, but
Of the object-oriented languages I know, pretty much all but C++ and Objective-C compile

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.