Answers for "php array_map"

PHP
5

using array map php

array_map ( callable $callback , array $array1 [, array $... ] ) : array
Posted by: Guest on April-27-2020
0

array_map()

<?php
function my_callback($item) {
  return strlen($item);
}


  $strings = ["apple", "orange", 
  "banana", "coconut"];
$lengths = 
  array_map("my_callback", $strings);
print_r($lengths);
?>
Posted by: Guest on September-16-2021
1

array map php

The array_map() function sends each value of an array to a user-made function, and returns an array with new values, given by the user-made function.

Tip: You can assign one array to the function, or as many as you like.

Syntax
array_map(functionname, array1, array2, array3, ...)
  
Example
Send each value of an array to a function, multiply each value by itself, and return an array with the new values:

<?php
function myfunction($val)
{
  return($val*$val);
}

$a=array(1,2,3,4,5);
print_r(array_map("myfunction",$a));
?>
Posted by: Guest on April-01-2020
0

php array_map

PHP function array_map(?callable $callback, array $array, array ...$arrays) array
-----------------------------------------------------------------------------  
Applies the callback to the elements of the given arrays.
  
Parameters:
callable|null--$callback--Callback function to run for each element in each array.
array--$array--An array to run through the callback function.
array--...$arrays--[optional]
  
Returns: an array containing all the elements of arr1 after applying the callback function to each one.
Posted by: Guest on September-11-2021
-1

array map php key, $value

$test_array = array("first_key" => "first_value", 
                "second_key" => "second_value");

var_dump(array_map_(function($key, $value){
    return $key . " loves " . $value;
}, $arr));
Posted by: Guest on October-04-2021

Browse Popular Code Answers by Language