<?php
/**
* Strips metadata from a list of items.
*
* @param array $data The input array of data.
* @return array The array with metadata stripped.
*/
function stripMetadata(array $data): array
{
$strippedData = [];
foreach ($data as $item) {
if (is_array($item)) {
$strippedItem = [];
foreach ($item as $key => $value) {
if ($key !== '_meta' && $key !== '_id') { //Exclude meta and id keys
$strippedItem[$key] = $value;
}
}
$strippedData[] = $strippedItem;
} else {
$strippedData[] = $item; //If not an array, just keep the item as is.
}
}
return $strippedData;
}
//Example Usage:
/*
$data = [
['id' => 1, '_meta' => ['author' => 'John Doe', 'date' => '2023-10-27'], 'title' => 'My Article'],
['id' => 2, '_meta' => ['author' => 'Jane Smith', 'date' => '2023-10-28'], 'title' => 'Another Article'],
'plain text'
];
$strippedData = stripMetadata($data);
print_r($strippedData);
*/
?>
Add your comment