Filter some values from an array in a serialized post_meta (PHP)

前端 未结 2 1166
余生分开走
余生分开走 2021-01-24 15:21

I have setup in Wordpress a custom post type ( Artists )...

I have a plugin that serializez the meta information from the Artists .. and i need to filter this informatio

相关标签:
2条回答
  • 2021-01-24 15:37

    Array filter was a good try, did you do it like this :

    $channel = 'trance';
    $show_data = array_filter($show_data, function($data) use ($channel) {
        return $data['channel'] == $channel;
    });
    
    0 讨论(0)
  • 2021-01-24 15:38

    You can do it by array_filter() using any key has value.

    For e.g Channel => trance then it will return matched arrays.

    $value = 'trance';
    $key = 'channel';
    
    $show_data = array_filter($array, function($itrate) use ($value,$key) {
        return $itrate[$key] == $value;
    });
    

    See : Live Demo

    0 讨论(0)
提交回复
热议问题