We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8531
    • 12 Posts
    Hey there ModxWorld,

    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!
      • 3749
      • 24,544 Posts
      It's possible, but it can't be a nested array.

      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;
      



        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting