• 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

Cant seem to get the Pagination to work on my WooCommerce REST API application?

JQuery content editable div and text box on submit not sending POST

How can i hide dt if dd got empty value

Issue with laravel eloquent model property

How to add automatically collapse/expand in content wordpress (single.php)?

Laravel print last executed SQL query with Query log

PHP Discord OAUTH2 code sample not working

virtctl works when executed via command line but not from php exec()

laravel MVC execution flow

How to pass data to all views in Laravel 5?

correct PHP headers for pdf file download

Access denied for user 'homestead'@'localhost' (using password: YES)

Parsing JSON File to array in PHP

Unable to create lockable file - Laravel 8 & PHP 8

Distribute array row data to make multiple new rows

About Contact Privacy policy Terms and conditions