error_reporting(E_ALL); function mpa_immo_wording_type_shooting($html, $typeShooting = 0) { $html = str_replace('photo', 'vidéo', $html); $html = str_replace('photos', 'vidéos', $html); // echo ("html : " . $html); return $html; } function mpa_immo_wording_type_shooting_recursive(&$array, $typeShooting) { try { if (empty($array)) { return; } if (!is_array($array) && !is_object($array)) { $array = mpa_immo_wording_type_shooting($array, $typeShooting); return; } if (!is_array($array)) { return; } foreach ($array as &$value) { mpa_immo_wording_type_shooting_recursive($value, $typeShooting); } // array_walk_recursive( // $array, // function (&$value) { // if (!is_array($value)) { // $value = mpa_immo_wording_type_shooting($value, $typeShooting); // } // } // ); } catch (Exception $err) { HelpersService::log($err); } } function transform_objects_to_array_recursive(&$data) { array_walk_recursive( $data, function (&$value) { if (!is_array($value) && is_object($value)) { $value = (array) $value; } } ); } function replaceTree($search = "", $replace = "", $array = false) { if (!is_array($array)) { // Regular replace return str_replace($search, $replace, $array); } $newArr = array(); foreach ($array as $k => $v) { // Replace keys as well? $add_key = $k; // Recurse $newArr[$add_key] = replaceTree($search, $replace, $v); } return $newArr; } function nmpaGetShootings() { $arr = array( "arr1" => array('chaine1' => "photo", "chaine2" => "photos"), "arr2" => array('test1' => "photos", "test2" => "photos"), "photos", ); $testarr = array("test1 obj" => "photos"); // $testobj = (object) (array("test1 obj" => "photos")); $shootings = array(new stdClass(), new stdClass()); foreach ($shootings as $shooting) { $testobj = new stdClass(); $testobj->test = "photos"; $testobj->test2 = "photos2"; $shootingsInfos = array(); $shootingsInfos['test'] = 'Veillez \u00e0 bien renommer vos photos de la fa\u00e7on suivante : R\u00e9f\u00e9rence du bien_Ville_Date du shooting_N\u00b0 de la photo. Formats demand\u00e9s 2/3extension \".jpg\", orientation paysage, taille 3000 x 2000 pixels, r\u00e9solution 300 DPI. Si une visite virtuelle a \u00e9t\u00e9 command\u00e9e, vous devez \u00e9galement la mettre en ligne le lien sur l\'espace pr\u00e9vu \u00e0 cet effet. Veillez \u00e0 bien renommer la visite 360 par le num\u00e9ro du shooting (ne jamais inscrire l\'adresse du bien). "'; $shootingsInfos['info_remuneration'] = $arr; $shootingsInfos['info_prestation'] = $testobj; $shootingsInfos['info_client'] = array("test1" => "test"); $shootingsInfos['info_package'] = array("test1" => "photos"); $shootingsInfos['info_cession_droits'] = array("test1" => "test"); transform_objects_to_array_recursive($shootingsInfos); mpa_immo_wording_type_shooting_recursive($shootingsInfos, 1); // echo ("shootingsInfos : " . print_r($shootingsInfos, true)); foreach ($shootingsInfos as $key => $shooting_info) { $shooting->$key = $shooting_info; } } return $shootings; } $newArray = nmpaGetShootings(); // $shootingsInfos = mpa_immo_wording_type_shooting_recursive($shootingsInfos, 1); // $shootingsInfos['info_remuneration'] = mpa_immo_wording_type_shooting_recursive($shootingsInfos['info_remuneration'], 1); echo ("shootingsInfos : " . print_r($newArray, true)); // echo ("test : " . !is_object($str)); // echo ("shootingsInfos : " . print_r($shootingsInfos, true)); //$arr = str_replace("test","testt",$arr); //echo ("AVANT : " . print_r($arr,true)); //echo "

"; //echo ( "APRES : " . print_r(str_replace("test","testt",$arr),true)); //echo ( "APRES : " . print_r(replaceTree("test","testt",$arr),true));