Questions tagged [array-map]

An array map function creates a new array by calling a callback function for each element of the provided input array. PHP: array_map( $callback, $input_array ), JavaScript: inputArray.map( callback ).

PHP's array_map() function accepts a callback function to run for each element in each array and an array to run through the callback function. It returns an array containing all the elements of arr1 after applying the callback function to each one.

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

array_map() — Applies the callback to the elements of the given arrays

Example:

function cube($n)
{
    return($n * $n * $n);
}
$a = array(1, 2, 3, 4, 5);
$b = array_map("cube", $a);
print_r($b);

Output:

Array
(
    [0] => 1
    [1] => 8
    [2] => 27
    [3] => 64
    [4] => 125
)
445 questions
-1
votes
1 answer

how can create new array from multiple array in codeigniter?

Two array given bellow , i want to first array first key and with second array second key and create new array. [animals1] => Array ( [0] => Horse [1] => Dog1 [1] => Cat ) [animals2] => Array …
jerry666
  • 19
  • 2
-1
votes
2 answers

Output form ArrayMap equals to null

I'm writing a parser to print a file json on my mobile. I include an ArrayMap to save data received from the file. My problem is that when I have to print data in a TextView, it returns null. I included the code under my question. ArrayMap
-1
votes
1 answer

array_walk returns true while method returns false for all elements

The check_access method below returns true but the check_access_level returns false for both the accountant and the marketer. What could be the problem? private static function check_access_level($value) { …
Tim Kariuki
  • 633
  • 8
  • 17
-1
votes
6 answers

how to multiply two array value without loop in laravel

I have tried to multiply $qty_test and $get_ltr also that data type is an integer, but that give me error Unsupported operand types what is issued in the code. $qty_test=explode(",",$request->input('qty')); foreach ($part_id as $part_ids) { …
dhara gosai
  • 92
  • 10
-1
votes
2 answers

Php Array Zipper - add two arrays by key value

I am trying to do this as efficiently as possible. I have multiple arrays: array1 = [ "2018" => [ "JAN" => 100, "FEB" => 200, "MAR" => 300, "APR" => 400 ] ] array2 = [ "2018" => [ "FEB" =>…
Cybergei
  • 39
  • 1
  • 7
-1
votes
1 answer

PHP : array_map with exponential function not working

I am trying to modify an entire associative array with a function. This is how the array looks like: Array ( [3] => 11 [1] => 12 [2] => 23 [0] => 34 [4] => 42 ) And this is the function: $bfactor = end($fballs) * log(100); function…
mirix
  • 511
  • 1
  • 5
  • 13
-1
votes
2 answers

Component Won't Render on Map Function

I'm using this component progress to draw a progress line. It works when I hardcode the values, but when I use it inside a map function it does not pick up the values. Can someone explain why this doesn't work?. import { Line, Circle } from…
webjunkie
  • 1,184
  • 9
  • 19
-1
votes
1 answer

Is it possible to divide the contents from an array into equal part/variable?

I am using print_r on a variable which gives me the following output Array ( [0] => 95.2 [1] => 94.7 [2] => 95 [3] => 33.6 ) Array ( [0] => 100 [1] => 95 [2] => 91.90000000000001 [3] => 33.6 ) I want to…
-1
votes
2 answers

I am reading csv file and what array_map() function does in this function?

In PHP, I want to read a ".CSV" file using the following function. function csv_to_array($filename='a.txt', $header_exist=true, $delimiter="\t") { if(!file_exists($filename) || !is_readable($filename)) return FALSE; $header =…
Premkumar chalmeti
  • 800
  • 1
  • 8
  • 23
-1
votes
2 answers

PHP array_map not returning resultant array

I am trying to replace an array value's spacing with hypen and then recollect back all values of the same array but with hypen in spaces. INPUT: $gFontsList = array("-1", "Agency FB", "28", "Aharoni Bold", "Bookshelf Symbol", "100", "Bookshelf…
Common Man
  • 103
  • 2
  • 13
-1
votes
2 answers

Php array_map unlink check if file exists

How do I check if the files exists in my array if I want to delete them with array_map + unlink: // deletes all jpg files in that path array_map('unlink', glob($path."/*.jpg")); Right now if the folder does not contain any .jpg files I get an…
utdev
  • 3,942
  • 8
  • 40
  • 70
-1
votes
3 answers

Create a new array with using 2 different arrays in php

I have 2 arrays like this. Array1: Array ( [abu-garcia] => 1 [daiwa] => 4 [shimano] => 4 ) Array 2: Array ( [0] => Array ( [brand_id] => 36 [brand_name] => Abu Garcia [brand_slug] =>…
kalle
  • 215
  • 3
  • 8
-1
votes
1 answer

htmlentities() returns empty string when used with an array

When I use htmlentities() to encode a variable it works like a charm, but if I do the same thing with an array it just returns an empty array. I tried to use array_map() but it's the same story. I tried to switch the encoding to ISO-8859-1 and UTF-8…
sgrontflix
  • 91
  • 1
  • 9
-1
votes
3 answers

Javascript - map and callback - returning values are not affected

I want to use map method on array with callback to another function. Everything seems to be working fine, but at the end returning values are not affected. I don't know what seems to be the problem. var arr=[4,5,3,2]; function multi (x,callback){ …
norbidrak
  • 463
  • 6
  • 22
-1
votes
1 answer

Alternative for array_map PHP 5.2

Something is wrong and I suspect it to be my PHP version that's 5.2 on this server; code was running on 5.6 before without any flaws... I have debugged it down to the following code that's breaking. However, I get no error message.. $standard =…
Joelgullander
  • 1,624
  • 2
  • 20
  • 46