I have an array like this:
$a = array('aa', 'bb', 'cc', 'dd');
I want to add the string 'rq' at the beginning of all elements of the array. Is it possible to do this by calling array_map () for this array?
$a = array_map(function ($str) { return "rq$str"; }, $a);
You can have it like this:
<?php $a = array('aa', 'bb', 'cc', 'dd'); $i=0; foreach($a as $d) { $a[$i] = 'rq'.$d; $i++; } var_dump($a); ?>
function addRq($sValue) { return 'rq'.$sValue; } $newA = array_map("addRq", $a);
Also see this example .
Source: https://habr.com/ru/post/1390964/More articles:What is the difference between collision resistance and prototype resistance? - securityHow to change eclipse hotkey? - javaThe array type of the 1-byte Android Heb type is extremely large - javaHow can I read the entire row of data from SQLite with FMDB in iOS dev? - iosAndroid double click capture - javajQuery and object oriented JavaScript - howto? - javascriptHow to get tweets using node.js - javascriptDisplay image via php file with Yii image content type - phpResultSet.next is very slow only when the request contains FIRST_ROWS or ROWNUM restrictions - javaUnable to get first method name in multicast deletion - c #All Articles