Thank you for the patience, I am fairly new to arrays, loops etc. One strange thing with the code gathered so far (example below):
$array = array(
'FIGURE1cy'=>10,
'FIGURE2cy'=>20,
'FIGURE1py'=>30,
'FIGURE2py'=>40,
'somethingelse'=>hello,
'somethingelse2'=>hello2
);
function ny($item) {
if (is_array($item)) {
foreach ($item as $key => $val) {
if (substr($key,-2) == 'py') {
$item[$key] = 0;
}
if (substr($key,-2) == 'cy') {
$key = str_replace("cy", "py", $key);
$item[$key] = $val;
}
if (substr($key,-2) == 'py') {
$key = str_replace("py", "cy", $key);
$item[$key] = $val;
}
}
return $item;
}
}
$b = ny($array);
echo json_encode($b);
This returns the following:
{"FIGURE1cy":30,"FIGURE2cy":40,"FIGURE1py":0,"FIGURE2py":0,"somethingelse":"hello","somethingelse2":"hello2"}
I was hoping it would have been:
{"FIGURE1cy":0,"FIGURE2cy":0,"FIGURE1py":10,"FIGURE2py":20,"somethingelse":"hello","somethingelse2":"hello2"}
The goal is to change this array:
$array = array(
'FIGURE1cy'=>10,
'FIGURE2cy'=>20,
'FIGURE1py'=>30,
'FIGURE2py'=>40,
'somethingelse'=>hello,
'somethingelse2'=>hello2
);to
$array = array(
'FIGURE1cy'=>0,
'FIGURE2cy'=>0,
'FIGURE1py'=>10,
'FIGURE2py'=>20,
'somethingelse'=>hello,
'somethingelse2'=>hello2
);