• 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

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_assoc() [duplicate]

phpmyadmin : Depends: php-twig (>= 2.9) but 2.6.2-2 is to be installed. WHAT?

How to access a var with "-" in PHP [duplicate]

Target Individual Form Instance/Counter Inside A PHP While Loop

Using Associative arrays

Laravel views are showing from cache on one server but works fine on other server

Filter array by skipping every nth element from the end

Load a .env file with PHP

Laravel dosen't connect with Oracle

Converting array to string and then back in PHP

Transpose multidimensional array and join values with commas

Eloquent insert id with sequence next value

Maatwebsite Excel 3.1 : how do I skip duplicate data when imported?

Yoast SEO (WordPress Plugin) - Get plugin generated data manually

About Contact Privacy policy Terms and conditions