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

  • Home
  • SEARCH
  • 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 8597843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:00:38+00:00 2026-06-12T01:00:38+00:00

I try to compare two arrays. First array is from my csv file and

  • 0

I try to compare two arrays. First array is from my csv file and second is $a – array. I try to get a csv data and add one more column from $a array data if there will not be the same value as in csv column 2 ( $line1 ) then show ’empty’

Now it shows only first value from array -> a (102019) others values show ’empty’;

As see everything is good but array a do not loop only once, where I am wrong? please show me … I spend today the whole day but nothing found.

<?php
    ////////////////////////////////////////////////////////////

    $file_path="".$_SERVER["DOCUMENT_ROOT"]."/upload/111.csv";

    ////////////////////////////////////////////////////////////

    $a = array('102019','102401','102403','102027','102115','102402','102027');

    function get_array_from_csv($file,$delimiter) {
      if (($handle = fopen($file, "r")) !== FALSE) {
        $i = 0;
        while (($lineArray = fgetcsv($handle, 4000, $delimiter)) !== FALSE) {
          for ($j=0; $j<count($lineArray); $j++) {
            $data2DArray[$i][$j] = $lineArray[$j];
          }
          $i++;
        }
        fclose($handle);
      }
      return $data2DArray;
    }

    function search($a, $line) {
        foreach($a as $mas_value) {
            if (substr($line[1], 2) == $mas_value) {
              $file = $mas_value;
            } else {
              $file = 'empty';
            }
            return $file;
        }
    }

    $data = get_array_from_csv($file_path, ';');

    echo '<table>';
    foreach ($data as $line) {

      $file = search($a, $line);

      echo '<tr>
        <td>'.$line[0].'</td>
        <td>'.$line[1].'</td>
        <td>'.$line[2].'</td>
        <td>'.$line[3].'</td>
        <td>'.$line[4].'</td>
        <td>'.$line[5].'</td>
        <td>'.$file.'</td>
      </tr>';
    }    
    echo '</table>';

    ?>

here is my output data:

ALFA ROMEO  BP102401    156 LIM 4D  1997-   20,00       empty
    BP102402    156 SPORT WAGON     2000-   20,00       empty
    BP102403    156 SPORT WAGON ar ugunsdzeЕЎ.  2000-   20,00       empty
    BP102404    159 -SW     2006-   22,00       empty
AUDI    BP102023    A 1     2010-   22,00       empty
    BP102023    A 1 Sportback   2010-   22,00       empty
    BP102001    A 2     2000-2005   15,00       empty
    BP102010    A 2 German  2000-2005   15,00       empty
    BP102002    A 3 HB  1996-2003   20,00       empty
    BP102013    A 3 HB  2003-   20,00       empty
    BP102004    A 4 AVANT/Combi     1994-2001   20,00       empty
    BP102012    A 4 AVANT/Combi     2001-2007   20,00       empty
    BP102019    A 4 AVANT /Combi    2008-   20,00       102019
    BP102005    A 4 LIM/SED     2000-2008   20,00       empty
    BP102003    A 4 LIM/SED     1994-2001   20,00       empty
    BP102018    A 4 LIM/SED     2008-   22,00       empty
    BP102018    A 5     2007-   22,00       empty
    BP102022    A 5 SPORTBACK   2009-   25,00       empty
    BP102007    A 6 AVANT/Combi     1997-2005   20,00       empty
    BP102016    A 6 AVANT/Combi     2005-2011   25,00       empty
    BP102026    A 6 AVANT/Combi     2011-   25,00       empty
    BP102007    A 6 AVANT QUATTRO   1997-2005   20,00       empty
    BP102006    A 6 LIM/SED     1997-2004   22,00       empty
    BP102014    A 6 LIM/SED     2004-2011   25,00       empty
    BP102025    A 6 LIM/SED     2011-   25,00       empty
    BP102011    A 6 LIM German  1997-2004   22,00       empty
    BP102007    A 6 ALLOROAD QUATTRO    2000-   20,00       empty
    BP102024    A 7 SPORTBACK   2010-   25,00       empty
    BP102027    Q 3 with a tool set located in the trunk    2011-   22,00       empty
    BP102028    Q 3 with an irregular size spare tire (space saver, smaller than standard tires)    2011-   22,00       empty

all values from array – a must be found in csv rows comparing with $line1

Full csv is uploaded here

  • 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-12T01:00:39+00:00Added an answer on June 12, 2026 at 1:00 am

    Try to change your search function as below

    function search($a, $line) {
            $file = 'empty';
            foreach($a as $mas_value) {
                if (substr($line[1], 2) == $mas_value) {
                  $file = $mas_value;
                  break;
                }
            }
            return $file;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Microsoft C compiler warns when you try to compare two variables, and one
When trying to compare two objects passed as arguments: first as object, second as
I'm trying to compare two millisecond values in Java. One from a calendar, and
i try to compare two lists with each other: ListA (a1,a2,a3,...) ListB (b1,b2,b3,...) I
I try to compare Mnesia with more traditional databases. As I understand it tables
I try to get some website attribute (colour of the cell) and compare in
With my following code I try to sort a two dimensional array int[][] d2
I am trying to compare two arrays that always have different dimensions. eg. arr1
I'm trying to compare four arrays. Two of the four arrays store filenames, while
I have an two arrays, one is cityUSA[i] and one is decimalUSA[i]. Each has

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.