• 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

Laravel Collections. Is there some kind of assertStructure method?

Group data in a multidimensional array based on two columns

How can i update or reset my password without entering email field in laravel-8?

Using if(isset($_POST['submit'])) to not display echo when script is open is not working

How to install LDAP in Docker php-fpm alpine

PHPUnit 7: Failed asserting that exception of type InvalidArgumentException is thrown

Laravel - Browser displays message again when I press back button

Apply filter array/return terms

Creating command to backup MySql database in Laravel

How to assert parameter attribute sub-structures in PHPUnit mock call expectations

PHP Array split string and Integers

PHP: PDO + CSV export not downloading (headers issue?)

How to render html from a @foreach loop in a textarea

PHP: convert all UTF-8 characters to HTML entities

How to Install Composer Require doctrine/dbal

About Contact Privacy policy Terms and conditions