TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   For each question (http://www.talkphp.com/general/5457-each-question.html)

CΛSTΞX 06-29-2010 12:19 AM

For each question
 
Hello,

PHP Code:

if(isset($videos[0]['url'])) {

            foreach (
$videos as $video)
            {

$yonlen $video['url'];
echo 
"<a href=$yonlen>Download</a><br>";
  } 

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 ?

delayedinsanity 06-29-2010 03:00 PM

That's hard to say without either seeing a copy of the array it's running off of, or the php that builds the data (and even then the data is probably still necessary).

CΛSTΞX 06-29-2010 03:10 PM

Ok, is there anyway to make number to the beginning of the values in for each statement ?

If 2 values echoed,

1 - Download
2 - Download

if 3 values echoed,

1 - Download
2 - Download
3- Download

?

tony 06-29-2010 03:32 PM

I have tried out your code sample and it works good for me with a mockup array

php Code:
<?php

$testarr = array();
$testarr[] = array("url" => "http://trying.com");
$testarr[] = array("url" => "http://trying1.com");
$testarr[] = array("url" => "http://trying2.com");
$testarr[] = array("url" => "http://trying3.com");
$testarr[] = array("url" => "http://trying4.com");
$testarr[] = array("url" => "http://trying5.com");

if(isset($testarr[0]['url'])) {
  foreach($testarr as $video) {
    $yonlen = $video['url'];
    echo "<a href=$yonlen>Download $yonlen</a></br>";
  }
}
?>

It doesn't echo it twice. Maybe if we know the structure of the array like delayedinsanity said it would be easier to help you out.

core1024 07-10-2010 02:52 PM

PHP Code:

$nl=0;
if(isset(
$testarr[0]['url'])) {
  foreach(
$testarr as $video) {
    
$nl++;
    
$yonlen $video['url'];
    echo 
"<a href=$yonlen>$nl - Download</a></br>";
  }




All times are GMT. The time now is 02:40 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0