Answer the question
In order to leave comments, you need to log in
How to build a multilevel array correctly?
Hello, I've been scratching my head for a very long time there is such a text (always different):
Название 1 | http://toster.ru/adsfasrew
Название 2 | http://toster.ru/eqweqsafds
...
Название 10 | http://toster.ru/gdftgrwet
Array
(
[0] => Array
(
[name] => 'Название 1'
[link] => 'http://toster.ru/adsfasrew'
)
[1] => Array
(
[name] => 'Название 2'
[link] => 'http://toster.ru/eqweqsafds'
)
...
[9] => Array
(
[name] => 'Название 10'
[link] => 'http://toster.ru/gdftgrwet'
)
Answer the question
In order to leave comments, you need to log in
$rows = explode("\n", $text);
$result = array();
foreach($rows as $row) {
list($name, $link) = explode('|', $row);
$result[] = array('name' => trim($name), 'link' => trim($link));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question