Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 09-04-2010, 11:25 PM if else and loops
Experienced Talker

Posts: 35
Trades: 0
I was wondering if I run a if statement inside of a loop if I can then use a else statement for it on the outside of that loop. The basic thing I am trying to do is compare all the values in an array to the id variable before proceeding to the else statement.
Direct is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-04-2010, 11:50 PM Re: if else and loops
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
An else block must be immediately preceded by an if or elseif. It sounds like you need to rethink your control flow. I'm sure if you can provide a more concrete example of what you're trying to do someone can help you out.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 09-05-2010, 12:06 AM Re: if else and loops
Junior Talker

Posts: 1
Name: Mahesh Agarwal
Location: Mumbai
Trades: 0
Quote:
Originally Posted by Direct View Post
I was wondering if I run a if statement inside of a loop if I can then use a else statement for it on the outside of that loop. The basic thing I am trying to do is compare all the values in an array to the id variable before proceeding to the else statement.
If your If-Else statement starts inside loop, you can not use a Else outside the loop statement.
__________________

Please login or register to view this content. Registration is FREE
snehalcreation is offline
Reply With Quote
View Public Profile Visit snehalcreation's homepage!
 
Old 09-05-2010, 12:55 PM Re: if else and loops
Experienced Talker

Posts: 35
Trades: 0
Well basically I am trying to do this

PHP Code:
foreach(blah){
    if(
something){
         
execute something ;
        }
}
else{
Do 
something if the if statement is false for all of the parts of the array


After some talks with some friends of mine I guess I can't do that. Is there any way you guys recommend going about this problem.
Direct is offline
Reply With Quote
View Public Profile
 
Old 09-05-2010, 05:14 PM Re: if else and loops
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Set a variable inside the if statement inside the loop and then use another if statement outside of the loops:
PHP Code:
$isTrue true;
foreach(
blah){
    if(
something){
         
execute something ;
         
$isTrue false;
        }
}
if(
$isTrue){
Do 
something if the if statement is false for all of the parts of the array

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Reply     « Reply to if else and loops
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15106 seconds with 12 queries