Category : array-map

Super quick question: Can I rewrite the following small piece of code: foreach ($countries as $c => $country) { $stats[$c] = count($country); } using array_map? Ie something like: $stats = array_map(‘count’, $countries); but then, I also want to associate each record of $stats to the key of the corresponding record of $countries! Thanks in advance ..

Read more

I am using the function array_map to transpore arrays The point is that it does work for small arrays, but with the arrays getting bigger the functions returns the following errors: Warning: Only arrays and Traversables can be unpacked in /web/htdocs/www.mosaic-dev.it/home/IA/ia2.php on line 379 Warning: array_map() expects at least 2 parameters, 1 given in /web/htdocs/www.mosaic-dev.it/home/IA/ia2.php ..

Read more

I am making an application where I have String which behaves like Array. e.g : String name = " "john","kat" "; I was trying to send them in php server(just sending the string wasn’t converting it to array). <?php if($_SERVER[‘REQUEST_METHOD’]==’POST’){ $names=array($_POST[‘name’]); $phones=array($_POST[‘phone’]); // $names = array("Hw", "V"); // $phones = array("656", "646"); array_map(function ($name, $phone) ..

Read more

I try to build a api with a good performance. This api should import product data via GuzzleHTTP into a shopsystem. I loop through the xml tags and map the features, if they’re assigned, with the corresponding uuids of the shopsystem. $articleData[‘properties’][X][‘id’] = property uuid of shopsystem It works fine. But it’s builded very static ..

Read more

I have a small bit of code that I’m using to output the initials of a group of names: $names = array("Tom Hanks", "Julia Roberts"); $initials = implode(‘/’, array_map(function ($name) { preg_match_all(‘/bw/’, $name, $matches); return implode(”, $matches[0]); }, $names)); echo $initials ; This outputs TH/JR. But what I would prefer is THank/JRobe where the first ..

Read more