For each question

Discussion in 'PHP' started by meannn, Jun 28, 2010.

  1. #1
    Hello,

    
    if(isset($videos[0]['url'])) {
    
    		    foreach ($videos as $video)
    		    {
    
    $yonlen = $video['url'];
    echo "<a href=$yonlen>Download</a><br>";
      }
    
    PHP:
    In for each statement, it generates 2 values to the $yonlen, the outputs is

    Download
    Download


    It echos 2 links. I want to make string equals to the latest value in for each statement. How to do that ?
     
    meannn, Jun 28, 2010 IP
  2. shubhamjain

    shubhamjain Active Member

    Messages:
    215
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #2
    Change the "download" to $yonlen
     
    shubhamjain, Jun 28, 2010 IP
  3. meannn

    meannn Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you for the reply but there nothing wrong with that part. The only thing is, it echos 2 values (download links) , I want to echo only latest one.
     
    meannn, Jun 28, 2010 IP
  4. themullet

    themullet Member

    Messages:
    110
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #4
    Sounds like you don't need the foreach then:

    if(isset($videos[0]['url'])) {
    
    $yonlen = $video[0]['url'];
    echo "<a href=$yonlen>Download</a><br>";
      }
    PHP:
     
    themullet, Jun 28, 2010 IP