K
K
Kirill Zhilyaev2016-04-22 00:26:42
PHP
Kirill Zhilyaev, 2016-04-22 00:26:42

How to join all the values ​​of two arrays into a string?

There are 2 arrays. It is necessary to glue all the values ​​of the first array into a string with all the values ​​of the second one.
For example
, 1 array: abc
2 array 1 2 3
The output should be a1 b1 c1 a2 b2 c2 a3 b3 c3
So far, nothing comes to mind except for two foreach.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
dev400, 2016-04-22
@kirill_782

yes, you can do that

$one = ["a","b","c"];
$two = ["1","2","3"];

foreach($one as $data) {

    foreach($two as $data1) {
        echo $data[0].$data1[0]."<br />";
    }

}

a1
a2
a3
b1
b2
b3
c1
c2
c3

S
Sergey, 2016-04-22
Protko @Fesor

So far, apart from two foreach, nothing comes to mind.

Yes, as if nothing better could be invented here.

K
Konstantin Khairov, 2016-04-22
@Kaylos

Just as an option to output through for loops double for if for

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question