avatar
extract values from an array based on IDs in PHP PHP
Input: list of array and string separate by comma.
$arrObject =  [["id"=>1,"name"=>"Sân Tennis"], ["id"=>2,"name"=>"Khu cách ly"]];
$stringIDs = "1,2,3";

$arrID = explode(",", $stringIDs);
$tempObjects = array();
foreach ($arrID as $item) {
    $globalIndex = $item;
    $obj = array_values(array_filter((array)$arrObject, function($obj) {
        if ($obj['id'] == $globalIndex) return $obj;
    }));
    if (sizeof($obj) > 0) {
        $obj = $obj[0]['name'];
    }
    $tempObjects[] = $obj;
}
You need to login to do this manipulation!