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.

Link to comment
Share on other sites

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);

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.