By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

if and foreach

exoskeleton
100+
P: 104
hi guys is there another way around to handle this stuff? this is my 2nd day ... :( ...i dont get it!

for example:

[PHP]foreach(xxxxxxxxxx) {

if (){xxxxxxxxxxxx}
elseif(){xxxxxxxxxx}
elseif(){xxxxxxxxxx}
elseif($x == foreach($y as $z) { $z }){xxxxxxxxxxxx}
else{xxxxxxxxxxxxxx}

}[/PHP]

something like that guyz..the last elseif statement i have to compare the value of the array...how can i do that? it wont work in this way

please help me... :(
Apr 27 '07 #1
Share this Question
Share on Google+
5 Replies


code green
Expert 100+
P: 1,726
The switch statement is normally used rather than multiple elseif. Although I sometimes find switch a little inflexible
Apr 27 '07 #2

100+
P: 136
Hi,

as I can understand in last elseif statement u r trying to search the value within an associative array. If this is the case then -
  • u can use array_search(), if u r looking for a particular value within the array.
  • u can use array_key_exists() if u r looking for a particular key.
if u r looking for something else then can u elaborate the probs little more?

susen
Apr 27 '07 #3

exoskeleton
100+
P: 104
Hi,

as I can understand in last elseif statement u r trying to search the value within an associative array. If this is the case then -
  • u can use array_search(), if u r looking for a particular value within the array.
  • u can use array_key_exists() if u r looking for a particular key.
if u r looking for something else then can u elaborate the probs little more?

susen
yes sir devsusen...im trying to compare the value within the array in my last elseif ...

i have an array then it should be compare to the value of $x for exampe:

[PHP]if($x==1) {
..................
} elseif($x==2) {
....................
} elseif($x==3) {
....................
}
} elseif($x==4) {
....................
} elseif($x== arrayvalue) { //<===array should be compare in this part
................
}else{
..........
}[/PHP]

the value of the array comes from the database! i cant place the IF STATEMENT inside the "foreach" anymore coz i already place it inside another foreach...if im goin to...it will displays the result repeatedly..so it must be on the part only...only in my last "elseif".

sir please help..if you have more question and need more details ... i will post it immediately...
Apr 28 '07 #4

exoskeleton
100+
P: 104
sir devsusen....THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! the array_search works!

OMG....thank you very much sir.... :)
Apr 28 '07 #5

100+
P: 136
feeling really good to help u :)

sir devsusen....THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! the array_search works!

OMG....thank you very much sir.... :)
Apr 28 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.