Jump to content

How would ANYONE append to every value within an array?


soma56

Recommended Posts

I can't seem to find an answer on this one. I've figured out how to add key/value pairs, add to the beginning and end - but the question here is how do you append to each value within an array?

 

Let's say I wanted to add the word 'go'.

 

From:

Array ( [0] => Bruins [1] => Rangers [2] => Leafs )

 

To:

Array ( [0] => GoBruins [1] => GoRangers [2] => GoLeafs )

 

Seems simple enough but Google isn't being friendly today.

Hey Thorpe, it's nice to see you're still hear helping people like me out. I thought of that but then how would I place all the $v back into the array? I hope that makes sense. The reason is because I have to combine it with another one...

 

<?PHP 
foreach ($arr as $k => $v) {
  $arr[$k] = 'go' . $v;
}
$combine = array_merge((array)$arr, (array)$anotherarray);
print_r($combine);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.