<![CDATA[ Key and values from array to placeholder(s) - My Forums]]> https://forums.modx.com/thread/?thread=104748 <![CDATA[Key and values from array to placeholder(s)]]> https://forums.modx.com/thread/104748/key-and-values-from-array-to-placeholder-s#dis-post-563329
I started to learn php and need some advice/help to understand how things are going.
When I have an array like this:
array (size=4)
  1 => 
    array (size=46)
      0 => 
        array (size=4)
          'drink' => string 'beer'
          'watch' => string 'boobs' 
          'need' => string 'coins'
          'when' => string 'now'
      1 => 
         array (size=4)
          'drink' => string 'whisky'
          'watch' => string 'bigger boobs' 
          'need' => string ' more coins'
          'when' => string 'now'
  2 => 
    array (size=46)
      0 => 
        array (size=4)
          'drink' => string 'milk'
          'watch' => string 'spongebob' 
          'need' => string 'icecream'
          'when' => string 'tomorrow'
      1 => 
         array (size=4)
          'drink' => string 'water'
          'watch' => string 'newstime' 
          'need' => string 'flatscreen'
          'when' => string 'yesterday'

...is it possible to assign keys and values directly to placeholders?
If yes - how?

Thanks a lot!]]>
effect-energy Dec 20, 2018, 07:42 AM https://forums.modx.com/thread/104748/key-and-values-from-array-to-placeholder-s#dis-post-563329
<![CDATA[Re: Key and values from array to placeholder(s)]]> https://forums.modx.com/thread/104748/key-and-values-from-array-to-placeholder-s#dis-post-563351
If the placeholders are in a chunk, you could reference your array like this:

$output .= $modx->getChunk('chunkName', $yourArray[0][1]);


If you need to set placeholders repeatedly using the same chunk, you could do it in a loop something like this (untested):

$output = '';

foreach ($myArray as $k => $v) {
   foreach($v as $j => $k) {
       $output .= $modx->getChunk('myChunk', $k);
   }
}

return $output;



]]>
BobRay Dec 22, 2018, 06:40 AM https://forums.modx.com/thread/104748/key-and-values-from-array-to-placeholder-s#dis-post-563351