N
N
not_eugen2019-07-15 23:21:51
PHP
not_eugen, 2019-07-15 23:21:51

How to add a few words to each line (Reproduction)?

There are N lines of the form:


site.com/file.php
site2.net/file.php
site3.irg/file.php

There are 10 lines of the form:

?123
?abc
?777

Please tell me how can I get a list in which each site will add the specified number of lines and links to multiply?
What should happen in the above example:
site.com/file.php?123
site.com/file.php?abc
site.com/file.php?777
site2.net/file.php?123
site2.net/file.php?abc
site2.net/file .php?777
...

Perhaps there is a ready-made program for this or you can use a bat script.
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Immortal_pony, 2019-07-16
@not_eugen

function crossConcat(array $someArray, array $otherArray) {
    $concatenated = [];
    foreach ($someArray as $someArrayElement) { 
        foreach ($otherArray as $otherArrayElement) {
            $concatenated[] = $someArrayElement . $otherArrayElement;
        }
    }
    return $concatenated;
}


$sites = ["site.com/file.php", "site2.net/file.php", "site3.irg/file.php"];
$paramStrings = ["?123", "?abc", "?777"];
var_dump(crossConcat($sites, $paramStrings));
/*
array(9) {
  [0]=>
  string(21) "site.com/file.php?123"
  [1]=>
  string(21) "site.com/file.php?abc"
  [2]=>
  string(21) "site.com/file.php?777"
  [3]=>
  string(22) "site2.net/file.php?123"
  [4]=>
  string(22) "site2.net/file.php?abc"
  [5]=>
  string(22) "site2.net/file.php?777"
  [6]=>
  string(22) "site3.irg/file.php?123"
  [7]=>
  string(22) "site3.irg/file.php?abc"
  [8]=>
  string(22) "site3.irg/file.php?777"
}
*/

A
Anton Shamanov, 2019-07-15
@SilenceOfWinter

цикл по файлам
   цикл по параметрам
      файл + параметр

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question