CKTIS / PHP
array_combine()
Use one list for the keys and another for the values of a new array.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
array_combine(array $keys, array $values): arrayUse one list for the keys and another for the values of a new array. Elements pair by iteration order, which is useful for attaching headings to a row of data. Duplicate keys collapse to the last associated value. In PHP 8 unequal list lengths raise a value error.
Signature
array_combine(array $keys, array $values): array
Example output
{"sku":"B2","qty":5}
Examples
<?php
$headings = ['sku', 'qty', 'qty'];
echo json_encode(array_combine($headings, ['B2', 3, 5]));
Result
{"sku":"B2","qty":5}