24 php
我有这个简单的数组,我想知道如何阻止显示前两个部分.
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]") ;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助都会很棒,谢谢!
kar*_*m79 105
用途array_slice
:
$output = array_slice($input, 2);
Run Code Online (Sandbox Code Playgroud)
Mos*_*hel 11
停止显示或删除?
删除:
$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);
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助!
array_slice($array, 2, count($array))
如果可能,使用或让您的正则表达式跳过前两个。
您还可以在数组上调用 array_shift() 两次。这可能更优化,因为它不需要复制数组。