foreach

Discussion in 'PHP' started by jeanmichel, Jun 25, 2010.

  1. #1
    hey people,

    is there a way of checking if a foreach finds Zero results.

    example, foreach loop goes through XML, if it finds a particular node->output the data.

    So if the foreach doesnt find the node it fails.
     
    jeanmichel, Jun 25, 2010 IP
  2. jeanmichel

    jeanmichel Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    need not find a solution-my brain stopped working for a second. It was an easy statement if(!empty($node->nodevalue)) { }
     
    jeanmichel, Jun 25, 2010 IP
  3. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #3
    ^^ try isset
     
    gapz101, Jun 25, 2010 IP
  4. themullet

    themullet Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #4
    another vote for isset, a quick look at phpbench shows that isset quicker
     
    themullet, Jun 25, 2010 IP
  5. w47w47

    w47w47 Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    just put an if statemenit in the foreach loop? :O

    easy as that.
     
    w47w47, Jun 25, 2010 IP
  6. jeanmichel

    jeanmichel Peon

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanks guys-it appears that isset is a far superior implementation.

    Thanks again.
     
    jeanmichel, Jun 26, 2010 IP