count (increment) question

Discussion in 'PHP' started by cgo85, Aug 28, 2008.

  1. #1
    With the code below I need to make the area that I've labeled '$count ++' start at 0 and be able to count without limit. I have something there but not sure if I'm on the right path. Thanks


    <?php
    
    $response = file_get_contents($request);
    
    if ($response === false) {
    die('Request failed');
    }
    
    $phpobj = unserialize($response);
    
    $content = '';
    foreach ($phpobj['value']['items'] as $business) 
    $content .= "{$business['0']['response']['LocationInfo']['neighborhood']['$count ++']['name']}";
    
    
    echo $content;
    
    ?>
    PHP:
     
    cgo85, Aug 28, 2008 IP
  2. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #2
    you must initialize the count first then increment every loop iteration, i dont get why you have a break there though, can you tell me what you want to achieve?
     
    serialCoder, Aug 28, 2008 IP
  3. cgo85

    cgo85 Peon

    Messages:
    380
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    i forgot to delete that when i posted it... it was something i was toying with. I don't really understand what how to do what you're talking about but would it start like this:

    <?php
    
    $response = file_get_contents($request);
    
    if ($response === false) {
    die('Request failed');
    }
    
    $phpobj = unserialize($response);
    $count = 0;
    $content = '';
    foreach ($phpobj['value']['items'] as $business)
    $content .= "{$business['0']['response']['LocationInfo']['neighborhood']['$count ++']['name']}";
    
    
    echo $content;
    
    ?>
    PHP:
     
    cgo85, Aug 28, 2008 IP
  4. serialCoder

    serialCoder Guest

    Best Answers:
    0
    #4
    ok, you can probably try this

    $content = '';
    $count = 0;
    foreach ($phpobj['value']['items'] as $business)
    {
    $content .= "{$business['0']['response']['LocationInfo']['neighborhood'][$count]['name']}";
    $count++;
    }
     
    serialCoder, Aug 28, 2008 IP
    cgo85 likes this.