我用simple_html_dom
抓取了Twitter媒体并得到了这个数组结果:
Array
(
[0] => https://pbs.twimg.com/media/DWyUfBdVwAE9bmJ.jpg
[1] => https://pbs.twimg.com/media/DWyUgBUVMAASB_g.jpg
[2] => https://pbs.twimg.com/media/DWyUg-xU0AEHdyL.jpg
)
Array
(
[0] => https://pbs.twimg.com/media/CYba_z2UwAAoSuC.jpg
)
Array
(
[0] => https://pbs.twimg.com/media/CTyJ52dUEAAirWw.jpg
[1] => https://pbs.twimg.com/media/CTyJ5yMUkAAbvZq.jpg
[2] => https://pbs.twimg.com/media/CTyJ5k4VEAAC4f7.jpg
[3] => https://pbs.twimg.com/media/CTyJ5f4VAAAZ08g.jpg
)
Array
(
[0] => https://pbs.twimg.com/media/CTyJJyeUcAAo8kt.jpg
[1] => https://pbs.twimg.com/media/CTyJJ2KUkAIKOPa.jpg
[2] => https://pbs.twimg.com/media/CTyJJycUkAAL29J.jpg
)
如何为每个阵列访问每个$value[0]
?
这是我的代码基于https://github.com/alexroan/twitter-scraper:
<?php
require 'TwitterScraper.php';
$feed = TwitterScraper::get_feed('maretaso_u');
foreach($feed as $tweet){
$media = $tweet->media;
echo "<pre>";
print_r($media);
echo "<pre>";
}
答案 0 :(得分:1)
示例:
$filtered = [];
foreach ($list as $values) {
$filtered[] = $values[0];
}
var_dump($filtered);
答案 1 :(得分:0)
我必须根据您提供的信息做出一些猜测。但这就是我所做的:
<?php
$feed = TwitterScraper::get_feed('maretaso_u');
$filtered = array_map(function($tweet) {
return $tweet->media[0];
}, $feed);
var_dump($filtered);