Home  >  Article  >  Backend Development  >  如何去除数组指定下标元素

如何去除数组指定下标元素

WBOY
WBOYOriginal
2016-06-13 12:08:421460browse

怎么去除数组指定下标元素

本帖最后由 lyf091 于 2014-10-19 12:14:29 编辑 直接上代码
<?php<br />require 'libs/config.inc.php';<br />$ch = curl_init("http://opac.hhit.edu.cn:8080/opac/openlink.php?strSearchType=title&strText=天才&displaypg=1000&sort=CATA_DATE&showmode=table");<br />curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 获取数据返回<br />curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); // 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回<br />$output = curl_exec($ch);<br />$output = preg_match('/<table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC" class="table_line" id="result_content" >(.*)<\/table>/isu', $output, $arr);<br />$output = preg_replace("'<tr[^>]*?>'si","",$arr[0]);<br />$output = preg_replace("'<table[^>]*?>'si","",$output);<br />$output = preg_replace("'<span[^>]*?>'si","",$output);<br />$output = preg_replace("'<td[^>]*?>'si","",$output);<br />$output = preg_replace("'</td>'si","",$output);<br />$output = preg_replace("'</span>'si","",$output);<br />$output = str_replace("</tr>","{tr}",$output);<br />$output = str_replace("\t","",$output);<br />$output = str_replace(" ","",$output);<br />$output = preg_replace('/ /',"",$output);<br />$output = preg_replace("'<[/!]*?[^<>]*?>'si","",$output);<br />$output = explode('{tr}', $output);<br />array_pop($output); //去除数组最后一个空元素<br />foreach ($output as $key => $value) {<br />	$value = trim($value);  <br />	$temp = explode("\r\n",$value);<br />	$output[$key] = $temp;<br />}<br />array_shift($output);<br />print_r($output);<br />exit;<br />$smarty->assign('arr',$output); //数组定义模板<br />$smarty->display('lib.html');<br />?>

想要去除红字的元素
Array
(
    [0] => Array
        (
            [0] => 1
            [1] => 天才少年维克多
            [2] => (美) 乔辛·迪·波沙达, 雷蒙德·乔伊著
            [3] => 南海出版公司2014.06

            [4] => I712.45/965
            [5] => 中文图书
        )

    [1] => Array
        (
            [0] => 2
            [1] => 维特根斯坦传:天才之为责任.插图本
            [2] => (英) 瑞·蒙克著
            [3] => 浙江大学出版社2014.04

            [4] => B561.59/14
            [5] => 中文图书
        )
)
分不多,全给了,十分感谢!
------解决思路----------------------
foreach($output as $k => $v) {
    unset($output[$k][2], $output[$k][3]);
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn