Is it possible to combine specific values in an array in php and if yes, how?

Joined
Jun 27, 2022
Messages
1
Reaction score
0
example:

$array1 = array(apple, orange, banana);
$array2 = array(juice, ade, flavour);

->array1+2 = array(applejuice, orangeade, bananaflavour)
 
Joined
Jun 24, 2022
Messages
4
Reaction score
0
Hello, lolich. You can use a third array as a placeholder, like so:
PHP:
$array1 = array("apple", "orange", "banana");
$array2 = array("juice", "ade", "flavour");
$array3 = array();

$array2value = "";
foreach ($array1 as $key => &$value) {
    $array2value = $array2[$key];
    array_push($array3, $value . $array2value);
}

echo "<pre>";
print_r($array3);
echo "</pre>";

Output:
Code:
Array
(
    [0] => applejuice
    [1] => orangeade
    [2] => bananaflavour
)

Cheers,
MrSevyu
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top