TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   if within a foreach ? (http://www.talkphp.com/absolute-beginners/3577-if-within-foreach.html)

Mithadriel 11-08-2008 10:52 PM

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?

Tanax 11-08-2008 11:46 PM

This is perfectly valid, except that you forgot the ";" marks:
php Code:
foreach ($key as $value) {
      if ($value == 0) {
          $variableone++;
      } elseif {$value == 1) {
               $variabletwo++; }
}

Mithadriel 11-09-2008 12:20 AM

Ah, thanks, silly mistake :)


All times are GMT. The time now is 10:58 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0