php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #35036 concatenate a string to each element of an array
Submitted: 2005-10-31 16:10 UTC Modified: 2005-10-31 16:20 UTC
From: thomas dot hebinck at digionline dot de Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.0.5 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: thomas dot hebinck at digionline dot de
New email:
PHP Version: OS:

 

 [2005-10-31 16:10 UTC] thomas dot hebinck at digionline dot de
Description:
------------
I'd like to have a fast function, which concatenates a string to each element of an array.

Reproduce code:
---------------
array array_concatenate ( array array, string string [, bool to_end=true])

Something like this as a php function:

$arr=array(1,2,3,4,5,6,7,8,9,0);
$str=' test';

array_walk($arr,create_function('&$elem','$elem .= "' . $str . '";'));


Expected result:
----------------
array ( 0 => '1 test', 1 => '2 test', 2 => '3 test', 3 => '4 test', 4 => '5 test', 5 => '6 test', 6 => '7 test', 7 => '8 test', 8 => '9 test', 9 => '0 test', )

Actual result:
--------------
;-)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-31 16:19 UTC] amt@php.net
Try join() or implode().
 [2005-10-31 16:20 UTC] amt@php.net
Actually, you are asking for something different. I don't 
think that will be added to the language, sorry.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 16:02:26 2025 UTC