Q:

Return row from an array if contains a value from another array with a different value format

I need to compare 2 different format arrays. The goal is to print from file1 only that rows which contain value from file2. 
I suppose that I have to load both files into 2 arrays and compare it. I tried array_intersect(), in_array() and array_key_exists(), nothing works for me. 
Here is the example of data files:
File 1:
2.26.81.0,4,10146128,10165054
82.132.227.75,7,10146130,10166530,10166093
91.206.0.35,10,10150898,10165809
88.145.18.102,3,10169097,10141126,21729395

File 2:
10146128
10146130

Result should looks like this: 
2.26.81.0,4,10146128,10165054
82.132.227.75,7,10146130,10166530,10166093

I have loaded both files in 2 arrays and I need to compare them now
$bought = fopen('f_data.csv', 'r');
$visited = fopen('l_data.csv', 'r');

$line = fgets($bought);
    while(! feof($bought)) {    
        $line = fgets($bought);
        $bought_f[] = $line;
    }

$line2 = fgets($visited);
    while(! feof($visited)) {   
        $line2 = fgets($visited);
        $visited_f[] = $line2;
    }   

A:

The functions you used didn't work because you converted the first file in an array putting each line into an array element, but since each line not a value but a list of values you should create a two-dimensional array (an array of arrays), so each array element contains just a value. For example you can do that using file() and explode():
// getting an array with an element for each line
$file1=file("file1.csv");
$length=count($file1);
// converting each line in an array of the comma-separated values
for ($i=0;$i<$length;$i++) {
  $file1[$i]=explode(",",$file1[$i]);
}
//for file2 using file() is enough as each line only contains one value
$file2=file("file2.csv");

In this way $file1[0][0] is2.26.81.0, $file1[0][1] is 4, $file1[0][2] is 10146128 and so on. Then, you have several options, the most basic one is using a double loop:
foreach ($file1 as $line) {
  foreach ($file2 as $value) {
    // code for checking if $value is contained in $line and store/print the result 
  }
}

Depending of what you need using in_array() for comparison and implode() for converting the line back to a comma-separated string would do the job.
Also note that if the first file can contain several values of the second file in the same line you can get duplicate results, in that case the solution would be stop checking the values of the second array as soon as you get a match.

