问题
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