Search
 
SCRIPT & CODE EXAMPLE
 

PHP

PHP array_map()

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

$strings = ["apple", "orange", "banana", "coconut"];
$lengths = array_map("my_callback", $strings);
print_r($lengths);
?>
Comment

what is array_map in php

array_map():
Send each element of an array to a user defined function, return an array as 
it or if required value can be process and return back new value given by the 
user defined function:

<?php

function funTable($el){
    return $el*2;
}
	
$arrMap = array(1,2,3,4,5,6,7,8,9,10);
$table = array_map('funTable',$arrMap);
print_r($table);
?>
Output:

Array
(
    [0] => 2
    [1] => 4
    [2] => 6
    [3] => 8
    [4] => 10
    [5] => 12
    [6] => 14
    [7] => 16
    [8] => 18
    [9] => 20
)
Comment

array_map in php

$test_array = array("first_key" => "first_value",
                    "second_key" => "second_value");
array_walk($test_array, function(&$a, $b) { $a = "$b loves $a"; });
var_dump($test_array);

// array(2) {
//   ["first_key"]=>
//   string(27) "first_key loves first_value"
//   ["second_key"]=>
//   string(29) "second_key loves second_value"
// }
Comment

using array map php

array_map ( callable $callback , array $array1 [, array $... ] ) : array
Comment

map array php

<?php
function cube($n)
{
    return ($n * $n * $n);
}

$a = [1, 2, 3, 4, 5];
$b = array_map('cube', $a);
print_r($b);
?>
Comment

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.
Comment

PREVIOUS NEXT
Code Example
Php :: Laravel API Endpoint "401 Unauthorized" on Server But Works Fine On Localhost 
Php :: array join pgp 
Php :: laravel wrong timestamp 
Php :: wordpress - php settings 
Php :: php interval day value 
Php :: laravel seeder 
Php :: get data from csv file in php and print in table 
Php :: remove all items of an array except the last 5 in php 
Php :: php apns notification source code 
Php :: PHP MySQL Insert Multiple Records 
Php :: laravel passport Route [login] not defined 
Php :: laravel import csv to database 
Php :: add custom shortcode in contact form 7 
Php :: contact form 7 in page template 
Php :: validate names regex php 
Php :: SQLSTATE[42S02] lumen 
Php :: laravel-enum 
Php :: php get multiple url parameters 
Php :: drupal 7 db_query example 
Php :: 2 days left format in laravel 
Php :: laravel log package, laravel log, save laravel log 
Php :: laravel casts AsCollection 
Php :: lastinsertId php 
Php :: laravel drop column softdeletes 
Php :: php get all days between two dates 
Php :: how change resource route parameters lravel 
Php :: install multiple php versions windows xampp 
Php :: PHP stripcslashes — Un-quote string quoted with addcslashes() 
Php :: joomla print query 
Php :: how to disable screenshot jquery 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =