0

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!

2 Answers 2

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.

1
  • Oh, wow, i guess i am tired!! but the second slash is a separator :) not a mistake. Thanks!!
    – J. A.
    Commented Mar 18, 2019 at 21:52
0

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

Your Answer

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

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