从阵列中删除前 2 个

php
2022-08-30 14:20:34

我有这个简单的数组,我想知道如何阻止前2个片段显示。

if(preg_match_all('/<td[^>]*class="sourceNameCell">(.*?)<\/td>/si', $printable, $matches, PREG_SET_ORDER));{
foreach($matches as $match) {

$data = "$match[1]";

    $array = array();
    preg_match( '/src="([^"]*)"/i', $data, $array ) ;
    print_r("$array[1]") ;
}

任何帮助都会很棒,谢谢!


答案 1

使用array_slice

$output = array_slice($input, 2); 

答案 2

停止显示或删除?

用于删除:

$array = array();
preg_match( '/src="([^"]*)"/i', $data, $array ) ;

// The following lines will remove values from the first two indexes.
unset($array[0]);
unset($array[1]);
// This line will re-set the indexes (the above just nullifies the values...) and make a     new array without the original first two slots.
$array = array_values($array);
// The following line will show the new content of the array
var_dump($array);

希望这有帮助!


推荐