Question: I have some data here

```
 VAN,Ford,Transit,7995
 VAN,Ford,Transit,8900
 VAN,Ford,Transit,6200

```

I have already split the data but I need to order them from cheapest van first and I have no idea where to start. Here is my code so far:

```
import java.io.BufferedReader;
import java.io.FileReader;

public class Vehicle {
    public static void main(String[]args) throws Exception
    {
        FileReader file = new FileReader("C:/Users/Aaron/Documents/java/car_file.txt");
        BufferedReader reader = new BufferedReader(file);
        String text = "";
        String line = reader.readLine();
        while (line!= null)
        {
            text += line+"\r\n";
            line = reader.readLine();
        }

        System.out.println(text);       
    }
}

```

I am guessing you make classes and sort the data some how but I don't know where to start.

Answer: 
Loop through the first array and check if the value of `$arr['id']` exists under the second array of ids. If found, add a flag as true or 1 , else false or 0.

```
foreach($arr1 as $k=>&$arr) //<--- As you can see I have  added & (Reason below)
{
   in_array($arr['id'],$arr2) ? $arr['hasID']= true : $arr['hasID']=false;
}

print_r($arr1);

```

[`Working Demo`](https://eval.in/137912)

**Reason** : To modify the array directly , you use the reference operator.

### One-liner `array_walk()`

```
array_walk($arr1,function (&$v,$k) use($arr2){ in_array($v['id'],$arr2)? $v['hasID']=true : $v['hasID']=false; });

```
Your try is not working because you use double == instead of simple = for value attribution. This should works :

```
foreach($a as $ak => $av) {
    foreach($b as $bk => $bv) {     
        if($bv == $ak['id']) {
            $a[$ak]['hasID'] = true;   
        } else {
            $a[$ak]['hasID'] = false;
        }
    }
}

```

However the solution with in\_array is a better choice for performance reason.