0

I need a help to solved my problem, I have a problem with detail as below: I have two array which:

$array_one = array('php', 'mysql');
$array_two = array('sample', 'nothing', 'glass', 'table', 'door', 'mirror', 'wall');

I have foreach $array_two as below:

echo '<pre>';
foreach($array_two as $item){
    $data = $item . ' + php or mysql for in sequence';
    print_r($data);
}
echo '</pre>';

I want to get result as below:

Array
(
    [0] => sample php
    [1] => nothing mysql
    [2] => glass php
    [3] => table mysql
    [4] => door php
    [5] => mirror mysql
    [6] => wall php
)

How to do it, in squence php and mysql into foreach a array.

Note: The $array_two no limit data. above only example. And the $array_one maybe added one or two again later.

Thanks.

2 Answers 2

1

Try this:

$n_one = count($array_one);
foreach($array_two as $i => $item) {
    $data = $item. '+'. $array_one[$i % $n_one];
    print_r($data);
}
Sign up to request clarification or add additional context in comments.

Comments

1

Try

foreach($array_two as $key=>$val){
  $result[] =  $val." ".$array_one[$key%2];
}

See demo here

1 Comment

Hello, I just try another answer and solved, thanks for your help, I just get you a vote up....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.