Free Web Hosting Forum
(#1 (permalink))
Old
Member
willettmatter is on a distinguished road
 
Posts: 61
Join Date: Jan 2012
Location: Idaho
Default hip hip array! - 02-06-2012, 05:00 AM

here is the snippit:
foreach($piz->toppings as $top)
{
$t=$top;
if($_POST[$t])
since $top is an array I cannot use it as a key. how can I make $t this instance of $top not the array?
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
Leder678's Avatar
Senior Member
Leder678 is on a distinguished road
 
Posts: 1,430
Join Date: Jan 2009
Location: Norway
Send a message via MSN to Leder678
Default 02-06-2012, 06:26 AM

class {....
var $toppings = array('top' = 1, 'newbeginner' = 2);

And then, to get the KEY, you do:
PHP Code:
foreach($piz->toppings as $key => $val) {
  if(
$_POST[$key]) {
   return;
  }

or the way it seems you wish to do it:
PHP Code:
foreach($piz->toppings as $t => $top {
  if(
$_POST[$t]) {
   return;
  }



Follow me on twitter @Mortenrb

W3Fools - Read and learn

Please AT LEAST read the 10 bolded lines of the TOS at:
http://www.000webhost.com/includes/tos.php

Last edited by Leder678; 02-06-2012 at 06:28 AM.
Reply With Quote
Reply

Tags
array, php

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com