• Welcome to Simple Machines Community Forum. Please login or sign up.
November 28, 2021, 11:56:02 AM

News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord


need help changing an each to a foreach

Started by shadav, October 18, 2021, 12:27:33 PM

Previous topic - Next topic

shadav

ok so trying to update some things and get rid of depreciated notices
but I've no clue really what I'm doing, looking online the each() needs to be rewritten to a foreach()

so this is the line of code
    while((list($key, $val) = each($menu_buttons)) && $key != 'search')
        $fnd++;

so er??? is this correct?
foreach(($menu_buttons as $key => $val) && $key != 'search')
        $fnd++;
--
edit: so I gave it a shot and nope  :laugh: that does not work
Parse error: syntax error, unexpected 'as' (T_AS)

Kindred

I don't think you can use && in a foreach definition.
Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.<br /><br />"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

Diego Andrés

Perhaps something like this

foreach($menu_buttons as $key => $val)
{
if ($key == 'search')
break;

$find_me++;
}

Where you find that? I've seen that in adk portal? Or an old mod from smfpacks probably

SMF Tricks - Free & Premium Responsive Themes for SMF.

shadav

Quote from: Diego Andrés on October 18, 2021, 02:14:11 PMPerhaps something like this

foreach($menu_buttons as $key => $val)
{
if ($key == 'search')
break;

$find_me++;
}

Where you find that? I've seen that in adk portal? Or an old mod from smfpacks probably

thank you that does work but now getting
Undefined variable: find_me  :laugh:  :laugh:

and yeah it's  SMFPacks Dynamic Directory
I reported it to them back in march and they just said to ignore the error
I already paid live to help before to do some custom coding on the mod for me since nibogo was busy
well I can't really ignore it anymore as php 7.2 is now obsolete
I'm using 7.3 for this site but would like to be able to move to 7.4

so I'll have to update things on my own it seems, hopefully with some help from folks here when I have no clue what I'm doing ;D

Diego Andrés

Oh it's actually $fnd, the name of the var I didn't read correctly, just verify that

SMF Tricks - Free & Premium Responsive Themes for SMF.

shadav

changed find_me to find
still
8: Undefined variable: find

but I can live with that if undefended variable is my only error  :D

Diego Andrés

You fell for the same, it says $fnd not $find  :P

SMF Tricks - Free & Premium Responsive Themes for SMF.

shadav

son of a....  :laugh:  :laugh:  :laugh:
ok changed to $fnd++;
no more errors
thank you  :)

shadav

test running php 7.4, no errors atm so all seems good...i'll give it a few days and see what may pop up

thank you

Advertisement: