-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 ?

10
  • 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. If you need more help than that you'll need to ask a clearer question and explain the situation fully.
    – ADyson
    Commented May 10, 2022 at 10:47
  • 1
    php.net/manual/en/function.explode.php
    – Justinas
    Commented May 10, 2022 at 10:48
  • Yes sorry for that. I can explode simple variables but when I see $this everything goes wrong :/ Commented May 10, 2022 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
    Commented May 10, 2022 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
    Commented May 10, 2022 at 10:50

2 Answers 2

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.

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
  • 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
    Commented May 10, 2022 at 11:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.