if and foreach

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • exoskeleton
    New Member
    • Sep 2006
    • 104

    if and foreach

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

    for example:

    [PHP]foreach(xxxxxxx xxx) {

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

    }[/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... :(
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    The switch statement is normally used rather than multiple elseif. Although I sometimes find switch a little inflexible

    Comment

    • devsusen
      New Member
      • Feb 2007
      • 136

      #3
      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_exist s() if u r looking for a particular key.

      if u r looking for something else then can u elaborate the probs little more?

      susen

      Comment

      • exoskeleton
        New Member
        • Sep 2006
        • 104

        #4
        Originally posted by devsusen
        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_exist s() 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...

        Comment

        • exoskeleton
          New Member
          • Sep 2006
          • 104

          #5
          sir devsusen....THA NK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! the array_search works!

          OMG....thank you very much sir.... :)

          Comment

          • devsusen
            New Member
            • Feb 2007
            • 136

            #6
            feeling really good to help u :)

            Originally posted by exoskeleton
            sir devsusen....THA NK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! THANK YOU! the array_search works!

            OMG....thank you very much sir.... :)

            Comment

            Working...