Tried this:
$array = array(
'FIGURE1cy'=>100,
'FIGURE1py'=>100,
'FIGURE2cy'=>100,
'FIGURE2py'=>100 ,
'somethingelse'=>hello,
'somethingelse2'=>hello2
);
function remove(&$item) {
foreach ($item as $key => $val) {
if (substr($key,-2) == 'py') {
unset($item[$key]);
}
}
}
$b = array_map("remove", $array);
echo json_encode($b);
But get the error:
Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/htdocs/phptest2/script/jsonnewyear.php on line 21
Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/htdocs/phptest2/script/jsonnewyear.php on line 21
Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/htdocs/phptest2/script/jsonnewyear.php on line 21
Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/htdocs/phptest2/script/jsonnewyear.php on line 21
Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/htdocs/phptest2/script/jsonnewyear.php on line 21
Warning: Invalid argument supplied for foreach() in /Library/WebServer/Documents/htdocs/phptest2/script/jsonnewyear.php on line 21
{"FIGURE1cy":null,"FIGURE1py":null,"FIGURE2cy":null,"FIGURE2py":null,"somethingelse":null,"somethingelse2":null}