I have an array as follows
$posts = array(
0 => array('user' => 'Charlie', 'message' => 'First message'),
1 => array('user' => 'Charlie', 'message' => 'Second message'),
2 => array('user' => 'Charlie', 'message' => 'Third message TEXT!'),
3 => array('user' => 'Charlie', 'message' => 'Fourth message')
);
and I’d like to replace “TEXT” with “NEXT” if it’s inside the message.
How could i do this?
I tried with
foreach ($posts as $r)
{
$r['message'] = str_replace('TEXT', 'NEXT', $r['message']);
}
But seems not to be working.
1 Answer