-1

I have an issue and I am stack in this many days now. I am new in PHP so I cannot understand totally concerning variables. Here is my code

<div class="<?php echo $this->class; ?> block filter <?php echo $this->field('schema')->value(); ?> <?php echo $this->field('align')->value(); ?><?php if($this->field('margin_top')->value()): ?> <?php echo $this->field('margin_top')->value(); ?><?php endif; ?><?php if($this->field('margin_bottom')->value()): ?> <?php echo $this->field('margin_bottom')->value(); ?><?php endif; ?><?php if($this->field('margin_top_mobile')->value()): ?> <?php echo $this->field('margin_top_mobile')->value(); ?><?php endif; ?><?php if($this->field('margin_bottom_mobile')->value()): ?> <?php echo $this->field('margin_bottom_mobile')->value(); ?><?php endif; ?>" <?php echo $this->cssID; ?><?php if ($this->style): ?> style="<?php echo $this->style; ?>"<?php endif; ?>>
    <div class="ce_portfoliofilter_content">
        <?php echo "Aktuelle Projekte in&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" ?>
        <?php foreach($this->group('filter') as $i => $fields): ?>
        <a data-filter=".filter_<?php echo standardize($this->field('name#'.$i)->value()); ?>">
            <?php if($this->field('icon#'.$i)->value()): ?><i class="<?php echo $this->field('icon#'.$i)->value(); ?>"></i><?php endif; ?>
            <span class="name"><?php if($this->field('label_items#'.$i)->value()): ?><?php echo $this->field('label_items#'.$i)->value(); ?><?php else: ?><?php echo $this->field('name#'.$i)->value(); ?><?php endif; ?></span>
        </a>
        <?php endforeach; ?>
        <a data-filter="*" class="all <?php if(\Input::get('filter') == ''): ?>selected<?php endif; ?>"><?php echo $this->field('label')->value(); ?></a>
    </div>
    <i class="mobile-filter-trigger fa fa-filter"></i>
</div>

<script type="text/javascript">
/* <![CDATA[ */
jQuery(document).ready(function(){ 
    jQuery('.ce_portfoliofilter .mobile-filter-trigger').click(function(){
        jQuery('.ce_portfoliofilter').toggleClass('mobile-filter-show');
    });
});

/* ]]> */
</script>
 

I need the filter-data with the field(name#) to accept more than one values, separated with comma(,) .

Do I have to explode or implode the array? and How I can target to that field ?

  • 1
    Please be clear - remember we cannot see your data or read your mind. Are you saying that `$fields` is an array? Show us exactly what it contains. If you want to know "how to explode" on a basic level you can [read the manual](https://www.php.net/manual/en/function.explode.php). If you need more help than that you'll need to ask a clearer question and explain the situation fully. – ADyson May 10 '22 at 10:47
  • 1
    https://www.php.net/manual/en/function.explode.php – Justinas May 10 '22 at 10:48
  • Yes sorry for that. I can explode simple variables but when I see $this everything goes wrong :/ – Nick Zagkanas May 10 '22 at 10:48
  • So what _exactly_ is in `$fields`? `var_export($fields);` and paste the results (or a sample of them, if it's too big) into your question. – ADyson May 10 '22 at 10:48
  • Also though it seems like the names you need are not actually in `$fields`, but somewhere else? What does `standardize($this->field('name#'.$i)->value()` return? – ADyson May 10 '22 at 10:50
  • BTW `explode` turns a string into an array. But you're trying to `echo`, and you can't echo an array, so perhaps you need `implode` instead (to turn an array into a string)? https://www.php.net/manual/en/function.implode.php – ADyson May 10 '22 at 10:50
  • standardize stringify the output of parethnesis – Nick Zagkanas May 10 '22 at 10:51
  • That's meaningless to us. what parenthesis, exactly, anyway? Please don't be vague...again, we are not looking over your shoulder. Show an actual example of the output. – ADyson May 10 '22 at 10:51
  • oh man.. why you are so aggresive? I'm trying my best please – Nick Zagkanas May 10 '22 at 10:53
  • Sorry if you think it's agressive, that's not the intention, however we are spending time to try and help, but when we ask something we just get vague information. We don't want to waste anyone's time including yours, so we just ask direct questions and give direct advice. Sometimes it can be blunt, sorry - we're just trying to get information as fast as possible, that's all. It's not a chat forum or an etiquette class. – ADyson May 10 '22 at 10:55

2 Answers2

1

If I understand correctly, it looks as though your foreach just needs to be in a different place like so:

<a data-filter="
    <?php foreach($this->group('filter') as $i => $fields): ?>
        .filter_<?php echo standardize($this->field('name#'.$i)->value()); ?>
    <?php endforeach; ?>
">

Structure may be too complex for simple implode.

Mark
  • 1,006
  • 1
  • 6
  • 6
0

It looks like you need an implode function instead of explode to get it into a single string. Check:

>>> $filters = ['foo', 'bar'];
=> [
     "foo",
     "bar",
   ]
>>> implode(',', $filters);
=> "foo,bar"
  • 1
    By the way, having the separator as the second parameter and the array as the first in the implode function is depreciated and will be removed in 8.0. – Mark May 10 '22 at 11:02