arrayutils
  • Home
  • 📖How to use?
    • âš¡Installation
  • 📖Methods
    • âš¡Static method
      • static from()
      • static of()
      • static mapToArray()
    • âš¡Generic method
      • join()
      • every()
      • some()
      • reduce()
        • reduceRight()
      • sum()
      • pop()
      • shift()
      • includes()
      • keyExists()
      • indexOf()
      • find()
        • findIndex()
      • first()
        • keyFirst()
      • last()
        • keyLast()
      • random()
        • keyRandom()
      • splice()
    • âš¡Chain method
      • chunk()
      • column()
      • combine()
      • concat()
        • concatSoft()
      • countValues()
      • diff()
        • diffAssoc()
        • diffKey()
      • fill()
        • fillKeys()
      • filter()
      • flat()
        • flatMap()
      • flip()
      • forEach()
      • intersect()
        • intersectAssoc()
        • intersectKey()
      • keys()
      • map()
        • mapAssoc()
        • mapKey()
      • pad()
      • push()
      • replace()
      • reverse()
      • slice()
      • sort()
        • sortKey()
      • unique()
      • unshift()
      • values()
  • 📖Suffixes
    • âš¡Suffix - From
    • âš¡Suffix - As
  • links
    • 📌Github repo
    • 📌Packagist project
    • 📌Poggit project
Powered by GitBook
On this page
  • Syntax
  • Parameter
  • Return value
  • Prefixing
  • References
  1. 📖Methods
  2. ⚡Chain method

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

  • 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

Previouscolumn()Nextconcat()

Last updated 4 years ago

$valueArray

PHP: array_combine - Manual
Logo