6
I have the following script:
<?php
$recursos_data = array(
array(
"id" => "0",
"recurso_nome" => "madeira",
"producao" => "%produz%",
"estoque" => "200"
),
array(
"id" => "1",
"recurso_nome" => "comida",
"producao" => "%produz%",
"estoque" => "100"
)
);
foreach($recursos_data as $recurso):
$retornar = preg_replace("/%produz%/", '500', $recursos_data[$recurso['id']]);
endforeach;
return $retornar
?>
I want to give a print_r
, return all array lines.
when I give a print_r inside the foreach, it shows all rows of the example array:
Array ( [id] => 0
[recurso_nome] => madeira
[producao] => 500
[estoque] => 200 )
Array ( [id] => 1
[recurso_nome] => comida
[producao] => 500
[estoque] => 100
)
and if I give a print_r
outside the foreach, only prints the last line of the array and also does not convert the %produces%:
Array ( [id] => 1
[recurso_nome] => comida
[producao] => %produz%
[estoque] => 100
)
after researching a lot, I discovered that you can add results using .=
only that I always get an error something like "you can’t turn array into string"