473,386 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

if and foreach

exoskeleton
104 100+
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
5 1798
code green
1,726 Expert 1GB
The switch statement is normally used rather than multiple elseif. Although I sometimes find switch a little inflexible
Apr 27 '07 #2
devsusen
136 100+
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
104 100+
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
104 100+
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
devsusen
136 100+
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

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

Similar topics

7
by: Phil | last post by:
Hi, I read somewhere that the new version (v1.1) has improved the performance of 'foreach' over 'for'. Is that true? I did some measurements and I still think for has an upperhand... ? Phil
32
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open...
8
by: cody | last post by:
currently, foreach takes a IEnumerable as parameter, so we can do: foreach (int i in array){} what about an additional form of foreach that takes an IEnumerator as parameter, so we can do: ...
104
by: cody | last post by:
What about an enhancement of foreach loops which allows a syntax like that: foeach(int i in 1..10) { } // forward foeach(int i in 99..2) { } // backwards foeach(char c in 'a'..'z') { } // chars...
3
by: cody | last post by:
why foreach does always have to declare a new variable? I have to write foreach (int n in array){} but Iam not allowed to write: int n=0; foreach (n in array){}
13
by: TrintCSD | last post by:
How can I reset the collections within a foreach to be read as a change from within the foreach loop then restart the foreach after collections has been changed? foreach(string invoice in...
27
by: Tripper | last post by:
Which is the better way to go and why? //trivial example List<string> strings = GetStrings(); foreach (string s in strings) { // some operation; } strings.ForEach(
3
by: Wiktor Zychla [C# MVP] | last post by:
since generics allow us to implement several IEnumerable<T> interfaces on a single class, I think that "foreach" should somehow reflect that. suppose we have a enumerable class class C :...
7
by: Osiris | last post by:
Just something I would like to share: I just learned the hard way (2 days detective work on a bug) that foreach loops are not at all like for loops, not intuitive at all. BEWARE: arrays and...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.