1

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?

user4560
  • 57
  • 1
  • 7
  • From what I can tell, you're trying to remove an element (or 2) from the array. This popular topic was addressed here: [Delete an element from an array](https://stackoverflow.com/questions/369602/php-delete-an-element-from-an-array) It discusses several ways to delete array elements using `unset()`, `array_splice()` and some others. Hopefully that gets you started in the right direction. – Amesh Jan 31 '19 at 17:53

1 Answers1

1

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);
João
  • 449
  • 4
  • 18