Home php Remove the last element of the array

Remove the last element of the array




Using the Simple HTML DOM parser, I get an array:

$ otveti_utf8_o = $ doc- & gt; find (". message");

I output this array in reverse order:

$ otveti_utf8 = array_reverse ($ otveti_utf8_o);

Now I need to remove the last element from this array.
Tried doing with array_pop function:

$ otveti_utf8_o = $ doc- & gt; find (". message");
$ otveti_utf8_a = array_reverse ($ otveti_utf8_o);
$ otveti_utf8 = array_pop ($ otveti_utf8_a);
for ($ i = 0; $ i & lt; count ($ otveti_utf8); $ i ++) {// remove the first item
  echo $ otveti_utf8 [$ i]. "& lt; hr / & gt;";


Cannot use object of type simple_html_dom_node as array in

How do I remove the last element of an array in my case?

Answer 1, authority 100%

it’s all about carelessness. the error does not occur when deleting an array element.

you removed the element

$ otveti_utf8 = array_pop ($ otveti_utf8_a);

and at this stage there are no errors. The error occurs on the following line:

for ($ i = 0; $ i & lt; count ($ otveti_utf8); $ i ++) {

more specifically, when trying to call count ($ otveti_utf8) , instead of obviously count ($ otveti_utf8_a) .
In this regard, there is such an error message that instead of an array, an object of the class simple_html_dom_node was passed (that is, the extracted element)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions