简体   繁体   中英

How do I add more than one quality inside a foreach

foreach($div->getElementsByTagName('a') as $link) {
$url = $link->getattribute('href');
$num = $link->nodeValue;   
echo '<source src="'.$url.'" type="video/mp4" label="----quality----" />';
}

The video link is repeated 5 times.. I want to add quality to each video [240-360-480-720-1080].. I searched a lot and did not find a solution to my problem and I hope that there is an example

Use the index in the foreach and then use this as the index into an array of qualities.

$qualities = [240, 360, 480, 720, 1080];

foreach($div->getElementsByTagName('a') as $index => $link) {
    $url = $link->getattribute('href');
    $num = $link->nodeValue;   
    $quality = $qualities[$index];
    echo '<source src="'.$url.'" type="video/mp4" label="----' . $quality . '----" />';
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM