Find character in php array

3

Imagining that I have the following array:

$o_meu_array = array("123_rui", "125_joao", "287_manuel");

Now I want to find inside my array "123". When I find 123, I want to replace 123 with another value given by the user. For example, if the user enters "10", it will be "10_rui". Is it possible to do this?

    
asked by anonymous 27.06.2014 / 16:32

1 answer

5

To replace values in an array you can use the preg_replace ()

$meu_array = array("123_rui", "125_joao", "287_manuel");
$procurar = "/123/";
$substituir = "10";
$meu_array = preg_replace($procurar, $substituir, $meu_array);

Example

    
27.06.2014 / 16:39