Skip to content

Instantly share code, notes, and snippets.

@johnregan3
Created November 15, 2013 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnregan3/7491125 to your computer and use it in GitHub Desktop.
Save johnregan3/7491125 to your computer and use it in GitHub Desktop.
Removing duplicate brightcove ID's
$playlist = array(
[0] => WP Post Object
[ID] => 1;
[_brightcove_id] = 1
[1] => WP Post Object
[ID] => 2;
[_brightcove_id] = 2
[2] => WP Post Object
[ID] => 3;
[_brightcove_id] = 1
);
//If duplicate _brightcove_id, remove latter array key (eg. [2])
@westonruter
Copy link

<?php
$playlist = array_filter(
    $posts,
    function ( $post ) {
        static $seen = array();
        if ( array_key_exists( $post->_brightcove_id, $seen ) ) {
            return false;
        }
        $seen[$post->_brightcove_id] = true;
        return true;
    }
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment