TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-08-2008, 10:52 PM   #1 (permalink)
The Wanderer
 
Join Date: Nov 2008
Posts: 5
Thanks: 2
Mithadriel is on a distinguished road
Default if within a foreach ?

Hi,

I'm not sure of the best way to do this and thought I might get a bit of help here ... hopefully :)

I have the contents of an array being fed out using a foreach loop, this works just fine and it displays everything as I would like.

What I was hoping to achieve however is that whenever X value appears within the array, I want it to count up on a variable.

So something like:

PHP Code:
foreach ($key as $value) {
      if (
$value == 0) {
          
$variableone ++
      } elseif {
$value == 1) {
               
$variabletwo ++ }

Am I going on completely the wrong track for what I want to do?
Mithadriel is offline  
Reply With Quote
Old 11-08-2008, 11:46 PM   #2 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

This is perfectly valid, except that you forgot the ";" marks:
php Code:
foreach ($key as $value) {
      if ($value == 0) {
          $variableone++;
      } elseif {$value == 1) {
               $variabletwo++; }
}
__________________
Tanax is offline  
Reply With Quote
Old 11-09-2008, 12:20 AM   #3 (permalink)
The Wanderer
 
Join Date: Nov 2008
Posts: 5
Thanks: 2
Mithadriel is on a distinguished road
Default

Ah, thanks, silly mistake :)
Mithadriel is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

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


All times are GMT. The time now is 04:56 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design