Skip to content

Instantly share code, notes, and snippets.

@lgedeon
Created July 14, 2020 02:36
Show Gist options
  • Save lgedeon/bcf0d8a0906b07e534175d801b9b5bb5 to your computer and use it in GitHub Desktop.
Save lgedeon/bcf0d8a0906b07e534175d801b9b5bb5 to your computer and use it in GitHub Desktop.
One way to normalize one particular type of multi-dimensional array.
<?php
return array_merge(
... array_map(
function( $key, $values ) {
if ( ! is_array( $values ) ) {
return [];
}
return array_map(
function ( $value ) use ( $key ) {
return [
'key' => $key,
'old_value' => $value
];
},
$values
);
},
array_keys( $post_meta ),
$post_meta,
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment