array_filter doesn't seems to work for words having apostrophe and dash

拥有回忆 提交于 2020-03-10 05:14:11

问题


I have a php code as shown below:

$scheduled_streams = \CTIME\LiveStreams\get_live_today_streams();  // Line A
echo '<pre>'; print_r($scheduled_streams); echo '</pre>';  // Line B
echo '<pre>'; var_dump($scheduled_streams); echo '</pre>';  // Line C
print_r(array_filter($scheduled_streams, function ($i) { return $i->program_title == 'Hello – Aujourd’hui'; }));  // Line D

Line B prints:

Array
(
    [0] => stdClass Object
        (
            [language] => en
            [post_id] => 319597
            [program_title] => Hello World
        )

    [1] => stdClass Object
        (
            [language] => en
            [post_id] => 319601
            [program_title] => Hello – Aujourd’hui
        )

)

Line C prints:

array (
  0 => 
  (object) array(
     'language' => 'en',
     'post_id' => 319597,
     'program_title' => 'Hello World',
  ),
  1 => 
  (object) array(
     'language' => 'en',
     'post_id' => 319601,
     'program_title' => 'Hello – Aujourd’hui',
  ),
)

Line D prints:

Array 
(
)

Problem Statement:

I'm wondering what PHP code I need to add so that it prints only the object which has [program_title] => Hello – Aujourd’hui

Array
(
    [0] => stdClass Object
        (
            [language] => en
            [post_id] => 319601
            [program_title] => Hello – Aujourd’hui
        )
)

This is what I have tried:

print_r(array_filter($scheduled_streams, function ($i) { return $i->program_title == 'Hello – Aujourd’hui'; }));

It prints;

Array
(
)

来源:https://stackoverflow.com/questions/60532447/array-filter-doesnt-seems-to-work-for-words-having-apostrophe-and-dash

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!