简体   繁体   中英

php foreach loop issue in IE11

I have very weird issue with php foreach loop in IE 11. In FF, Chrome, Opera, Safari, IE 7 8 9 10 Foreach loop works fine.

I used for() loop for dummy text it works fine in IE 11. But i don't know how to call arrays in for or while loop

here is my code.

$img_num4 = 4;
$data_chunks = array_chunk($wp_images, $num_img);

echo '<ul id="id1">';
    foreach ($data_chunks as $data_chunk) {
        echo '<li class="id2">';
        foreach($data_chunk as $data) {
                    if($data['image_links_to'])
                        echo '<a href="'.$data['image_links_to'].'" '.$new_window.'>';
                    echo '<img src="'.$data['file_url'].'" class="logo-img" alt="" />';
                    if($data['image_links_to'])
                    echo '</a>';
        }
        echo '</li>';
    }
echo '</ul>';

I don't know why foreach loop not working in IE 11 only. Any Suggestions.

I also try this:

$img_num4 = 4;
$data_chunks = array_chunk($wp_images, $num_img);

echo '<ul id="id1">';
    for($i=1; $i<=10; $i++){
            echo '<li>'.$i.'</li>';
        }
    /*foreach ($data_chunks as $data_chunk) {
        echo '<li class="slide">';
        foreach($data_chunk as $data) {
                    if($data['image_links_to'])
                        echo '<a href="'.$data['image_links_to'].'" '.$new_window.'>';
                    echo '<img src="'.$data['file_url'].'" class="logo-img" alt="" />';
                    if($data['image_links_to'])
                    echo '</a>';
        }
        echo '</li>';
    }*/
echo '</ul>';

It shows me correct data in IE 11. But foreach loop not work

please tell me how can i call arrays in for or while loop

With a for loop it should be like :

$img_num4 = 4;
$data_chunks = array_chunk($wp_images, $num_img);

echo '<ul id="id1">';
$len = $data_chunks.lenght;
for ($i = 0; $i < $len; $i++) {
    $data_chunk = $data_chunks[$i];
    echo '<li class="id2">';
    $len2 = $data_chunk.lenght;
    for ($j = 0; $j < $len2; $j++) {
        $data = $data_chunk[$j];
        if($data['image_links_to']) {
            echo '<a href="'.$data['image_links_to'].'" '.$new_window.'>';
        }
        echo '<img src="'.$data['file_url'].'" class="logo-img" alt="" />';
        if($data['image_links_to']) {
            echo '</a>';
        }
    }
    echo '</li>';
}
echo '</ul>';

a while loop is not so useful here.

As metionned in comments, php's an html preprocessor so it does not need any browser to work. Maybe you should look on the html source in your IE11 browser to see what is buggy.

MAYBE (and that's an important part of the sentence) IE11 doesn't display <li> if it does not contains any text. Here you only put an <img> (sometimes with a link).

You should try replacing img tag with text in your foreach loop.

Apolo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM