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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon May 20 18:01:36 2024 UTC