Jump to content

PHP foreach() exception to the rule.

- - - - -

  • Please log in to reply
4 replies to this topic

#1
JinWook

JinWook

    Newbie

  • Members
  • Pip
  • 3 posts
Hello Coders.

I have a piece of code here that fetches a URL based on a portfolio catagory.
In this case the url of every link will be /portfolio/"$portfolio_item name"


foreach($page_photo_arr as $key => $portfolio_item)

{					

     $image_url = ''; 


I'd like to make an exception to this rule in a couple of cases. I'm not sure what the correct syntax would be.

 foreach($page_photo_arr as $key => $portfolio_item)

  if ($key === 'home') {

                $url = 'the new url';

            }else {


This is what I've tried, it makes sense to me but it isn't working.

Any help would be appreciated. Thanks.

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Well, you're setting $url instead of $image_url, for starters. It would help if you provided a little more of the surrounding context, though.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
JinWook

JinWook

    Newbie

  • Members
  • Pip
  • 3 posts
Oh sure, sorry I forgot to paste my site I'm working on.
Kerry Bradford Art

At the top there is a nav bar that is directly connected to the portfolio section.
If you click on "Home" it should take you to Kerry Bradford Art but instead takes you to Home ‹ Kerry Bradford Art as per the code I mentioned above.
This is fine for the other portfolio menus, so I just want to make an exception for this particular item.

Thanks

#4
JinWook

JinWook

    Newbie

  • Members
  • Pip
  • 3 posts
Thanks for the reply. Sorry I forgot to to post the link previously.

The site I'm working on is Kerry Bradford Art

I'm trying to set the "Home" portfolio to send me to Kerry Bradford Art and not Home ‹ Kerry Bradford Art

I would assume it's a simple php exception, just not sure what the correct method is.


Thanks again.

#5
njr1489

njr1489

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
You're using the triple equals operator on the conditional which I find odd. Wouldn't == just do the trick since you're just checking for a string? And as WingedPanther said, you're not using your original $image_url. That variable should be assigned to $portfolio_item I take it.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users