Hello. Tell me why I have only the latest values ​​from each foreach loop in $ output? What needs to be corrected in the code?

<?php $ids = $modx->resource->get('id'); if ($product = $modx->getObject('msProduct', $ids)) { $output .= $product->get('pagetitle'); foreach ($product as $output) { $color = $product->get('color'); foreach ($color as $cval) { $output .= $cval; } $putkart = $product->get('put_kartinka'); foreach ($putkart as $putval) { $output .= $putval; } $nackart = $product->get('nacenka_kartinka'); foreach ($nackart as $ncval) { $output .= $ncval; } } } $output .= $modx->getChunk('Test', array('color' =>$cval, 'nacenka' => $ncval, 'putkart' => $putval) ); return $output; 

    1 answer 1

    All values ​​are concatenated (concatenated) in $output . Concatenate one, for example

     foreach ($resources as $res) { $output .= '<p>'.implode(',', $res->get('nacenka_kartinka')).'</p>'; } 
    • I did not understand something. In this case, he will display to me all the values ​​of their one field. For example, 1500, 2000, 3500. And I need him to output one of the values ​​in one pass of the cycle. - Batyabest
    • write an example of what you want to get - Alex
    • In the color field, such values ​​(for example) ["Wenge", "Oak dairy"] In the field put_kartinka ["/images/venge.jpg", ai/mages /dub.jpg"] In the field nacenka_kartinka ["1500", " 2000 ”] I need to make a conclusion so that all the first values ​​are output for the first round, then all the second values, etc. And I just everything in a bunch of displays. This will result in a block with the same values, a block with the second, and so on. <div> <div> Here from color </ div> <div> Here from put_kartinka </ div> <div> Here from nacenka_kartinka </ div> </ div> And so on. - Batyabest