• 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

Android Volley getParams() method not getting called for JsonObjectRequest

PHPUnit (Phar) Fatal Error Only When Test Fails

PHP my timezone is no setting up in PHP.ini File in xampp

Laravel Command Schedule Not Working Properly

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

how to upload binary image to sql server using php laravel

How do I call a php file with axios?

unable to load your default controller on Codeigniter

PHPMetrics option --excluded-dirs="myfolder" : myfolder dir is not excluded within docker

How to use a PHP MVC Controller, one thats invoked by calling a URL, to call and execute more than one function? [duplicate]

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

Using array_intersect on a multi-dimensional array

Encrypt in php and decrypt in Dart(flutter)

Google Calendar API batch request PHP

Undefined variable in Laravel 8 project (php 7.4)

About Contact Privacy policy Terms and conditions