Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: shadav on October 18, 2021, 12:27:33 PM

Title: need help changing an each to a foreach
Post by: shadav on October 18, 2021, 12:27:33 PM
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)
Title: Re: need help changing an each to a foreach
Post by: Kindred on October 18, 2021, 01:37:59 PM
I don't think you can use && in a foreach definition.
Title: Re: need help changing an each to a foreach
Post by: Diego Andrés on October 18, 2021, 02:14:11 PM
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
Title: Re: need help changing an each to a foreach
Post by: shadav on October 18, 2021, 02:33:50 PM
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
Title: Re: need help changing an each to a foreach
Post by: Diego Andrés on October 18, 2021, 02:39:00 PM
Oh it's actually $fnd, the name of the var I didn't read correctly, just verify that
Title: Re: need help changing an each to a foreach
Post by: shadav on October 18, 2021, 02:42:22 PM
changed find_me to find
still
8: Undefined variable: find

but I can live with that if undefended variable is my only error  :D
Title: Re: need help changing an each to a foreach
Post by: Diego Andrés on October 18, 2021, 02:44:17 PM
You fell for the same, it says $fnd not $find  :P
Title: Re: need help changing an each to a foreach
Post by: shadav on October 18, 2021, 02:56:30 PM
son of a....  :laugh:  :laugh:  :laugh:
ok changed to $fnd++;
no more errors
thank you  :)
Title: Re: need help changing an each to a foreach
Post by: shadav on October 18, 2021, 02:59:27 PM
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