I need to find and replace an element in an array. Is there any single php function for this?
3 Answers
You can simply use array_splice.
See example
$input = array("red", "green", "blue", "yellow");
array_splice($input, -2, 1, array("orange", "maroon"));
// $input is now array("red", "green", "orange", "maroon","yellow")
1 Comment
José Fernández Ramos
Your solution does not solve the problem of finding the element to be replaced.