1


I need to generate li item with data- attribute while array.length < 0
Got a problem while concatenation. In result it's wrong li I need: <li data-color='red, green, blue' data-size='1, 2, 3'>
But result is: <li data- color='red, green, blue' size='1, 2, 3'>

Code:

$filters_li = '<li class="textile-item"';

                foreach($filters_labels as $label){
                    foreach($filters_fields as $field){
                        $filters_li .= 'data-'.$label.'="'. get_labels_as_tags($field, 1) . '"';
                    }
                }

                $filters_li .= '>';

Where is problem, I can't understand

2 Answers 2

1

You may try trimming the $label to see your results like so :

    filters_li = '<li class="textile-item"';

                foreach($filters_labels as $label){
                    foreach($filters_fields as $field){
                        $filters_li .= 'data-'. trim($label) .'="'. get_labels_as_tags($field, 1) . '"';
                    }
                }

                $filters_li .= '>'; 

Maybe that does the trick for you

Sign up to request clarification or add additional context in comments.

Comments

1

you can use from trim function, this function remove spaces by default

$filters_li .= 'data-'.trim($label).'="'. get_labels_as_tags($field, 1) . '"';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.