• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Merge key and value of array index [duplicate]

phparrays


PHP Snippet 1:

$arr = ['foo'=>'bar','baz'=>'bat'];
$combine = array_map(fn($k, $v) => "$k: $v", array_keys($arr), array_values($arr));
print_r($combine);

PHP Snippet 2:

Array
(
    [0] => foo: bar
    [1] => baz: bat
)

PHP Snippet 3:

$arr = [ 'foo' => 'bar', 'baz' => 'bat' ];

$result = [];

array_walk($arr, function ($value, $key) use (&$result) {
  $result[] = "$key: $value";
});

Related Snippets

Unable to get password for the instance created from AMI

PHP: Calling MySQL Stored Procedure with Both INPUT AND OUTPUT Parameters (NOT "INOUT")

PHP Array split string and Integers

Target Laravelista is not instantiable

Json_Encode not returning html even i try to encode JSON_HEX_QUOT | JSON_HEX_TAG

Laravel Collections. Is there some kind of assertStructure method?

Cannot pass null argument when using type hinting

sort() not affecting original array while inside foreach loop

IlluminateDatabaseQueryException: SQLSTATE[HY000]: General error: 1 no such table - In clone project

How to override htaccees file for cache control header

SilverStripe unable to populate multiple member Childs

Lumen - Postgresql setup - Composer

Combine multiple columns into an array as one of the key in a results set

How to connect to MSSQL Server with PHP from Ubuntu 18.04?

Woocommerce Checkout - Add conditional field required if one field is filled

About Contact Privacy policy Terms and conditions