我有一个多维数组,如下所示:
Array (
[results] => Array (
[0] => Array (
[object_id] => 13
[id] => 13
[idno] => e00110-o00005-2010-PROG
[display_label] => La Bohème / PUCCINI - 2010
[ca_objects.description] => Libreto de Luigi Illica y Giuseppe Giacosa basado en Escenas de la vida bohemia de Henri Murger Nueva producción – Teatro Colón
[ca_objects.type_id] => Programa de mano
)
//more data here
我正在尝试循环数组并使用 str_replace 替换“new_id”的“object_id”键。
$str="object_id";//The string to search for
$rep="new_id";//The replacement string
foreach ($array as $value) {
foreach ($value as $key2 => $value2) {
foreach ($value2 as $key3 => $value3) {
str_replace($str,$rep,$key3);
echo $key3." : ".$value3."<br>"; //It gets printed with no changes
}
}
}
上面的代码不起作用,你能看到我做错了什么吗?我尝试使用字符串而不是变量,但也没有用。提前致谢。