如何访问这种数组值?
How to access this kind of array value?
我用 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>";
}
我不得不根据你提供的信息做出一些猜测。但这就是我所做的:
<?php
$feed = TwitterScraper::get_feed('maretaso_u');
$filtered = array_map(function($tweet) {
return $tweet->media[0];
}, $feed);
var_dump($filtered);
示例:
$filtered = [];
foreach ($list as $values) {
$filtered[] = $values[0];
}
var_dump($filtered);
我用 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>";
}
我不得不根据你提供的信息做出一些猜测。但这就是我所做的:
<?php
$feed = TwitterScraper::get_feed('maretaso_u');
$filtered = array_map(function($tweet) {
return $tweet->media[0];
}, $feed);
var_dump($filtered);
示例:
$filtered = [];
foreach ($list as $values) {
$filtered[] = $values[0];
}
var_dump($filtered);