Creating dynamic list element php

635


I need to generateli item withdata- attribute whilearray.length < 0
Got a problem while concatenation. In result it's wrongli 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

295

Answer

Solution:

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

277

Answer

Solution:

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

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

People are also looking for solutions to the problem: php - Find identical IP from database and combine it to one result

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.