PHP:具有3个值/键的字典的简单数据结构

I have a list of triangles each traingle has an id, perimeter and area.

I need to implement functions to find triangle in the list based on one of the parameters (id or perimeter or area).

The question is how to store the list in this case? I am looking for something simple, which will make these functions small.

I tried to use

$triangleList[$id] = [$area,$perimeter];

for each triangle to build assoc. array. But now a can't easily find the triangle based on area or perimeter (must use foreach, in_array is not enough).

Is there a simple way to do that?

Say you are looking for triangle with area=2 for example,

$subset = array_reduce($triangleList, function ($carry, $item) {
    if ($item['area'] == 2) {
        $carry[] = $item;
    }
}, array());

My solution, using three simple arrays in a class. Then using array_search for searching functions:

class ListOfTriangles {

private $ids = [];
private $areas = [];
private $perimeters = [];

public function addTriangle($id,$area,$perimeter){
    $ids[] = $id;
    $areas[] = $area;
    $perimeters[] = $perimeter;
}

public function getTriangle($index){
    return [$this->ids[$index],$this->areas[$index],$this->perimeters[$index]];
}

public function searchById($id){
    $index = array_search($id, $this->ids);
    return $this->getTriangle($index);
}

public function searchByArea($area){
    $index = array_search($area, $this->areas);
    return $this->getTriangle($index);
}

public function searchByPerimiter($perimiter){
    $index = array_search($perimiter, $this->perimiters);
    return $this->getTriangle($index);
}
}