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 :: php image rotate upload 
Php :: mysql Cannot pass parameter 2 by reference 
Php :: script inside php 
Php :: laravel modules 
Php :: how to get client ip address in php 
Php :: get all users created in a month laravel 
Php :: group_concat mysql limit issue 
Php :: laravel collection search 
Php :: remove behind comma php 
Php :: laravel use config 
Php :: call to a member function get_results() on null 
Php :: assigning variable in php 
Php :: post data to another page contact form 7 
Php :: signup form in php 
Php :: php query to hide duplicate records 
Php :: woocommerce get shipping classes 
Php :: acf wordpress loop through and display blog posts order by date and type 
Php :: laravel if else condition in blade file 
Php :: wp+get tags for custom post type 
Php :: last insert id mysqli 
Php :: if home else php wordpress 
Php :: php docs comments 
Php :: laravel db raw count where 
Php :: laravel migration column types 
Php :: laravel check if collection has value 
Php :: how do i know if file is empty in php 
Php :: php get first two paragraphs 
Php :: how to convert enum to string in php 
Php :: laravel mailable from 
Php :: ajax load more button wordpress 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =