C
C
Cheizer2019-11-24 20:16:36
MODX
Cheizer, 2019-11-24 20:16:36

How to populate an array in a FOREACH loop in MODX REVO?

There is such an array in the CMS MODX REVO plugin.
The essence of the plugin makes subdomains from the URL of the pages, but this is not about that.
Now 'pages1.site.ru' => 190, I add these entries by hand, but I want to do it automatically.
Each element of the array is an ALIAS and a page ID.

$domains = array (
    'pages1.site.ru' => 190,
    'pages2.site' => 161,
);

To get these aliases and page ids automatically in CMS MODX RREVO, I did this
if(!$docs = $modx->getCollection('modResource', array(
    'parent' => 15,
    'published' => 1,
    'deleted' => 0,
    'searchable' => 1
))){return;}

QUESTION. How to fill an array in a loop now?
To fill the $domains array automatically.
$domains = array (
    'pages1.site.ru' => 190,
    'pages2.site' => 161,
);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Araik, 2019-11-24
@Cheizer

foreach ($docs as $key => $value) {
$domains[$key] = $value;
}

I'm not sure what's right. I didn’t understand what $docs looks like, but I think you will understand the essence.
Well, the link is traditional foreach

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question