php - adding or removing endforeach; throws error!

admin2025-06-02  1

This is my code, where i keep getting either error: unexpected endforeach; if endforeach is used or unexpected end of file if i don't use endforeach; It's driving me crazy!!

<ul id="portfolio-filter">
    <?php
    $k=0;
    $services = array('all', 'marketing', 'SEO', 'web-design', 'web-development',                           'wordpress'); 
    foreach($services as $key) : ?>                     
    <li class="<?php if($k==0) { ?> active <?php { ?>"><a class="<?php echo $key; ?>" href="#"><?php echo $key; ?></a>/</li>
    <?php endforeach; ?> 
</ul>

Any help will be appreciated!

This is my code, where i keep getting either error: unexpected endforeach; if endforeach is used or unexpected end of file if i don't use endforeach; It's driving me crazy!!

<ul id="portfolio-filter">
    <?php
    $k=0;
    $services = array('all', 'marketing', 'SEO', 'web-design', 'web-development',                           'wordpress'); 
    foreach($services as $key) : ?>                     
    <li class="<?php if($k==0) { ?> active <?php { ?>"><a class="<?php echo $key; ?>" href="#"><?php echo $key; ?></a>/</li>
    <?php endforeach; ?> 
</ul>

Any help will be appreciated!

Share Improve this question edited Mar 18, 2019 at 21:44 WebElaine 9,8491 gold badge17 silver badges28 bronze badges asked Mar 18, 2019 at 21:41 J. A.J. A. 12 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 0

If you pasted your code directly,

The second curly bracket here <?php if($k==0) { ?> active <?php { ?> should be a closing one, like this:

<?php if($k==0) { ?> active <?php } ?>

There is also a stray slash </a>/</li> - should be - </a></li> - but that shouldn't cause any PHP errors.

Here is your full code

<ul id="portfolio-filter">
<?php
$k=0;
$services = array('all', 'marketing', 'SEO', 'web-design', 'web-development', 'wordpress'); 
foreach($services as $key) : ?>                     
<li class="<?php if($k==0) { echo "active"; } ?>"><a class="<?php echo $key; ?>" href="#"><?php echo $key; ?></a>/</li>
<?php endforeach; ?> 

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748793885a313769.html

最新回复(0)