Search
 
SCRIPT & CODE EXAMPLE
 

PHP

php associative array join key values

If you want to implode an array as key-value pairs, this method comes in handy.
The third parameter is the symbol to be used between key and value.

<?php
function mapped_implode($glue, $array, $symbol = '=') {
    return implode($glue, array_map(
            function($k, $v) use($symbol) {
                return $k . $symbol . $v;
            },
            array_keys($array),
            array_values($array)
            )
        );
}

$arr = [
    'x'=> 5,
    'y'=> 7,
    'z'=> 99,
    'hello' => 'World',
    7 => 'Foo',
];

echo mapped_implode(', ', $arr, ' is ');

// output: x is 5, y is 7, z is 99, hello is World, 7 is Foo

?>
Comment

associative array in php have same value join them


<?php
$a = array('green', 'red', 'yellow');
$b = array('avocado', 'apple', 'banana');
$c = array_combine($a, $b);

print_r($c);
?>

Comment

PREVIOUS NEXT
Code Example
Php :: set custome table laravel eloquent 
Php :: maintenance mode laravel 
Php :: create email template php 
Php :: php get first day of month 
Php :: get recoed between two datetime laravel 
Php :: composer create new laravel project 
Php :: laravel collection sort 
Php :: mysql get number of rows php 
Php :: select multiple option in laravel 
Php :: qr code generator php 
Php :: use php var in js 
Php :: convertir datetime a string en php 
Php :: if request type is post 
Php :: get date after 1 dayphp 
Php :: random string value laravel 
Php :: toggle between login and logout buttons php 
Php :: curl error (code 3) url malformed laravel 
Php :: cara membuat looping table dengan php 
Php :: php array_push in foreach duplicate 
Php :: drupal 9 guzzle client increase timeout 
Php :: php laravel dump 
Php :: php string random 
Php :: PHP str_word_count — Return information about words used in a string 
Php :: create model, controller and migration in single command laravel 
Php :: change default user table name laravel 
Php :: cmd disable wifi driver 
Php :: how to create singleton laravel 
Php :: twig log variable 
Php :: Method IlluminateSupportCollection::links does not exist. 
Php :: popular cms 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =