dqd54099 2019-01-31 17:38
浏览 182
已采纳

在foreach循环之前使用array_splice

I'm using php simple dom

I'm trying to clean up an array prior to a foreach loop, my code so far:

$html = file_get_html('test/php/refs.calendar.html');

$links = array();

foreach ($html->find('ul') as $ul) {

        $links[] = $ul->plaintext ;    

}

echo '<pre>',print_r($links, 1),'</pre>'; 


prints out:

Array
(
    [0] => bla bla
    [1] => more bla bla 
    [2] => some text
    [3] => some more text
    [4] => some more text
    [5] => some more text
)

prior to foreach loop i tried:

$links[] = array_splice($html->find('ul'), 1, 2) ;

I would like to get rid of array1 and [2] before the loop, I think i'm getting objects and arrays in a twizzle, any ideas guys?

  • 写回答

1条回答 默认 最新

  • dqc19941228 2019-01-31 18:01
    关注

    Instead of trying to splice before sending into the array, do it after:

        array_splice($links, 0,2);
        print_r($links);
    

    or unset:

        unset($links[0], $links[1]);
        print_r($links);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题