E
E
Extramezz2015-09-25 16:36:06
PHP
Extramezz, 2015-09-25 16:36:06

Concatenate arrays into a string, how?

Given:

$arr1 = array("one", "two");
$arr2 = array("p1", "p2");

How is it universal (for any equal number of elements in arrays) to merge this case into a string: one=p1&two=p2? Actually, the question is not even how, because I can do it foreach 'em. I'm wondering if there is a ready-made function / functions for solving this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tigra, 2015-09-25
@Extramezz

array_combine function

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

will display
Array
(
    [green]  => avocado
    [red]    => apple
    [yellow] => banana
)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question