Update the EA_Model::only method to use the array_fields function

This commit is contained in:
Alex Tselegidis 2022-10-16 18:04:49 +03:00
parent 98a0e07484
commit 54bc07f62a

View file

@ -169,14 +169,22 @@ class EA_Model extends CI_Model {
/** /**
* Only keep the requested fields of the provided record. * Only keep the requested fields of the provided record.
* *
* @param array $record Record data. * @param array $record Record data (single or multiple records).
* @param array $fields Requested field names. * @param array $fields Requested field names.
*/ */
public function only(array &$record, array $fields) public function only(array &$record, array $fields)
{ {
$record = array_filter($record, function ($field) use ($fields) { if (is_assoc($record))
return in_array($field, $fields); {
}, ARRAY_FILTER_USE_KEY); $record = array_fields($record, $fields);
}
else
{
foreach ($record as &$record_item)
{
$record_item = array_fields($record_item, $fields);
}
}
} }
/** /**