• 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

Transpose multidimensional array and join values with commas

VB.NET WebRequest with PHP POST

xdebug 3 not working in ubuntu 20.04 with docker

Converting IPv6 to IPv4 address in PHP

PHP contact form configuration [duplicate]

Warning file_get_contents () failed to open stream: HTTP request failed! HTTP/1.0 402 Payment Required

How do I call Validator from a namespace with an already existing Validator class

Search for array row with specific column value and return another value from qualifying row

How to loop a tree array with unknown depth and get array blocks?

PHP file_get_contents function

WooCommerce Additional Information - if empty, hide

Adding reCAPTCHA v2 into my PHP file

Normalize DateInterval in PHP

How to make a array inside array?

How to trim a video by 4 fragments to 4 seconds using the PHP-FFMpeg?

About Contact Privacy policy Terms and conditions