arrayutils
Search
⌃K

combine()

The combine() method returns new array by using one array for keys and another for values
Example.php
<?php use kim\present\utils\arrays\ArrayUtils;
​
$arrayUtils = ArrayUtils::from(["first", "second", "third"]);
​
//General usage
$arrayUtils->combine([1, 2, 3]);
// expected output: ["first" => 1, "second" => 2, "third" => 3]
​
//Combine itself
$arrayUtils->combine();
// expected output: [
// "first" => "first",
// "second" => "second",
// "third" => "third"
//]

Syntax

$arrayUtils->combine(iterable|null $valueArray = null) : ArrayUtils;

Parameter

  • $valueArray
    An array of elements to use as values. Default is NULL. If is null, Use itself.

Return value

  • A combined array.
If the number of elements for each array isn't equal, It will be throw error

Prefixing

$arrayUtils->combineAs(iterable|null $valueArray = null) : array;
ArrayUtils::combineFrom(iterable $from, iterable|null $valueArray = null) : ArrayUtils;
ArrayUtils::combineFromAs(iterable $from, iterable|null $valueArray = null) : array;

References

​
Last modified 2yr ago