This is my array:
$my_array = array("1", "2", "3", "4", "5");
How can I return the deleted item after using shuffle($my_array) and array_pop($my_array)?
I want something like: The deleted number is: 3.
This is my code:
$my_array = array("1", "2", "3", "4", "5");
shuffle($my_array)
array_pop($my_array)
How can I achieve this?
According to the PHP documentation, array_pop() will return the value that was deleted:
Return Values
Returns the value of the last element of array. If array is empty (or is not an array), NULL will be returned.
So, you can simply do:
$my_array = array(1, 2, 3, 4, 5);
shuffle($my_array);
echo 'The deleted number is: <b>'.array_pop($my_array).'</b>';