Foreach loop help . . .

If anyone knows of the Nintendo Wii Virtual Console; that’s good, I am making a ‘simple’ calculator that allows you (regardless of region) to find how many Wii points you would have after you downloaded some retro games onto the Wii. All I need is help with a foreach loop. Here is the PHP file (that does the interpreting of the form):

[php]<?PHP
// ======================================================================

// NORTH AMERICA
// ======================================================================

$_PRICES[‘NES’] = 500;
$_PRICES[‘SNES’] = 800;
$_PRICES[‘N64’] = 1000;
$_PRICES[‘GEN’] = 800;
$_PRICES[‘TURBO’] = 600;
//---------------------------------------------------------------------------
// SOUTH AMERICA
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// EUROPE
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// ASIA
//---------------------------------------------------------------------------
/*
$_PRICES[‘FAM’] = 500;
$_PRICES[‘SFAM’] = 800;
$_PRICES[‘N64’] = 1000;
$_PRICES[‘MASTER’] = 800;
$_PRICES[‘PC’] = 600;
*/
//---------------------------------------------------------------------------
// OTHER
//---------------------------------------------------------------------------

$total = 0;

foreach ($_PRICES as $current_game)
{

}

?>[/php]

Early December I had help with this same thing from my brother; it went onto a (currently down) ‘server’ as such I can’t get the code but from the 1st calclulator I remember the loop having:

$_POST in it (I think $_POST[‘before’]), $total, +=, $current_game**********. And another variable that I can’t remember the name or what it was set as.

Also as I said before the PHP file interpreted a form which is:

[code]

Virtual Console Calculator Welcome one, welcome all! To this Virtual Console Calculator. This script is to help you decide on what Virtual Console games you'd like to download onto your Nintendo Wii. Simply check the boxes of the game(s) you'd like to download & (how many wii points you'd have after the last download is done), and input (at the bottom) amount of Wii points you have, and submit.
Nintendo Entertainment System Donkey Kong Mario Bros Pinball Soccer Solomon's Key Legend of Zelda Wario's Woods Donkey Kong Jr Ice Hockey Tennis Super Mario Bros Baseball Urban Champion
Super Nintendo Entertainment System F-Zero SimCity Street Fighter II: The World Warrior Super Castlevania IV
Nintendo 64 Mario 64
Sega Genesis Altered Beast Sonic The Hedgehog Ecco the Dolphin Golden Axe Columns Ristar Dr. Robotnik's Mean Bean Machine Gunstar Heroes Space Harrier II ToeJam & Earl
Turbo Grafix 16 Bomberman '93 Bonk's Adventure Super Star Soldier Victory Run Alien Crush Military Madness R-Type
[/code]

Think someone could help me? To confusing/long? Also: the loop does NOT use functions (like count(), rand(), mt_rand(), no functions); also it does not use things OTHER than those. That’s what the oringinal used, i’m trying to replicate it exactly and the oringinal had those (and some other things whch I can’t remember) and only those.

I had a better answer to this one, but the forum rejected it.

Try this out.

[php]
$prices = array(
‘NES’ => 0,
‘SNES’ => 0,
‘N64’ => 0,
‘TURBO’ => 0,
// …
);

foreach( $_POST as $key => $value )
if( is_array( $value ) && array_key_exists( $key, $prices ) )
$prices[$key] = count( $value );
[/php]

You know what? I give the damn hell up, I don’t give a damn FIN care if I get banned from this forum. I said in my other post that the array:

Also: the loop does NOT use functions (like count(), rand(), mt_rand(), no functions); also it does not use things OTHER than those {the $current_game, etc). That’s what the oringinal used, i’m trying to replicate it exactly and the oringinal had those (and some other things whch I can’t remember) and only those.

No IF statements, no is_array, is_numeric, in_array, Just on line using: $_POST*{‘before’}, $current_game, $total, +=, and that’s about it.

Why would you want to do that?

Oh, and sorry about not reading all your mess, I had a hard time finding out what was the question in the first place.

I don’t see why you want to get that attitude with somebody trying to help you. Replicating it exactly as it was may not even be the best idea, perhaps the idea could be improved upon if you just approached with a fresh start with the help of some outside people.

Sponsor our Newsletter | Privacy Policy | Terms of Service