<?php
error_reporting(E_STRICT);
$test = 'love';
$eff = end(explode('ov',$test));
var_dump($eff);
?>
it will work fine if your error reporting level is not set to E_STRICT
.
See, when you have an temporary array returned, you cannot just set the internal pointer just like this. You need to set it to a variable first then move the internal pointer to the end using end()
.
This is true so for: reset()
, next()
, prev()
and so on.
The following would work instead.
<?php
error_reporting(E_STRICT);
$test = 'love';
$a = explode('ov',$test);
$eff = end($a);
var_dump($eff);
?>
current()
works because it does not move the internal pointer, but to get what the current element that the internal pointer is pointing at.