Good afternoon guys, well the problem is the following ..
I have a string named x, and I have two arrays, name and value.
in both arrays I identify if in the string X has some field equal to $ name, if it has substitution by $ value,
Is there any way to run it when it overwrites and saves in a single string all changed fields? Sample code below:
Note the string is an array, so it replaces the values one by one.
$valor = array('1', '2');
$nome = array('valor1', 'valor2');
$x = "Esse é meu valor1 e meu valor2";
for ($i=0; $i<$cc; ++$i) {
$string[$i] = str_replace($nome[$i], $valor[$i], $x);
echo $string[$i];
echo "<br />";
}
Answer that I want="This is my 1 and my 2"; Answer that goes out the way the code is="This is my 1 and my value2" "This is my value1 and my 2"
Edit: The values I placed there were for simplifying the problem, $ name and $ value are dynamic, can have N values, $ cc is the number of elements that make up both arrays
Edit 2: Sorry for not being clearer, the question I'm trying to solve is this, I have string with name Ex: "Component + General cost", $ name is the name of each component, eg $ name ('Component', 'General costs'), I have inputs that are generated dynamically, I'm rescuing these inputs from the value typed and the id of the component that dps got the name in the database, so for each component (every $ name) I have a value, what I really want is for example it will get the name arrays and replace with the corresponding value of array $ value (that hi $ would represent the position of both in array)
Edit 3: I have the values 0 => 10,1 => 20 in the array $ value, and 0 => Costs, 1 => Expenses in the $ name array, and a string named "Costs - Expenses, "for i $ would not replace both, and would be the final value of the string" 10 - 20 ", is what I want to get, since he is currently generating" 10 - Expenses "and in sequence" Costs - .
The code: link