$fav = explode("|","0 | 1 | 2 | ");
print_r($fav);
$fav = array_pop($fav);
echo "<br>after <br>";
print_r($fav);
what's the problem in my code? i want to remove the last value in the array $fav.
Remove the assigment, so it looks like this:
array_pop($fav);
array_pop returns the removed value and modifies the array in-place, so you must not assign the return value to the array variable.
you've overwritten the variable $fav.
you also might want to remove the last | from your string that you explode.
<?php
$fav = explode("|","0 | 1 | 2");
print_r($fav); // output should be: 0, 1, 2
$last_element = array_pop($fav);
echo "<br>after <br>";
print_r($fav); // output should be: 0, 1
?>