• 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

Sort multidimensional array by column value within a column

mysql_result is defined but mysql_free_result warns it expected a resource

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

Filter array by skipping every nth element from the end

possible options to create pdf file using html elements to generate invoice in php and codeigniter

how to make my own auto increment in php?

How to pass security cloudflare server with php curl

SMTP ERROR: MAIL FROM command failed: 530 5.7.0 Must issue a STARTTLS command first when using PHPMailer

How to unlink image from folder?

Form repeater send wrong data with last element in Laravel

Get WooCommerce products from specific category

NGINX: connect() to unix:/var/run/php7.2-fpm.sock failed (2: No such file or directory)

Laravel You requested 1 items, but there are only 0 items available

PHP: Insert marker every 3 iterations

Getting public posts of a random user from Facebook API

About Contact Privacy policy Terms and conditions