• 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

How to make a array inside array?

Symfony process run throws exception - executing on command line works

Is there an equivalent of DynamoDB on Azure as a PHP session Handler

Losing session data after POST from third party website

how do i retrieve and display the alt text of an image in wordpress?

Unable to Edit config.inc.php

Sync Records With Default Values in Pivot Tables, Call to undefined method syncWithPivotDefaults()

laravel 5.6 bulk inserting json data

Add Class in html Dynamically in PHP

Laravel : How to Create Dropdown to Select FOREIGN KEY from Other Table?

Laravel with App Engine Standard Class 'FacadeIgnitionIgnitionServiceProvider' not found

How to submit a form when page loads using JavaScript?

Reducing authentication calls on external API (Laravel 5.6)

Check if a string contain multiple specific words

PDOException SQLSTATE[HY000] [2002] No such file or directory

About Contact Privacy policy Terms and conditions