I need to remove a parameter within an array, change the value, then put it back into the array.
This is how I'm initially getting the values:
<?php
$value = $_POST['criteria'];
$valueSet = isset($value['countries']) ? $value['countries'] : '';
$valueSplit= explode(",", $valueSet);
$valueFinal = "'". implode("','", $valueSplit) . "'";
echo $valueFinal;
?>
Using the above, the $valueFinal
variable can look like this:
'USA','CAN','FRA'
I need to be able to check if 'FRA' exists in the array, remove it from the array, change it to 'GER', then put it back into the array.
In the end, the $valueFinal
array should look like this:
'USA','CAN','GER'
I am not sure if this is possible. How can I make this work?
Edit
I am able to use the following to check if the value exists:
if(in_array("FRA", $valueSplit)
But I am not sure how to update that single value, then add it back to the array.