我想知道我是否可以在我的php中多次使用字符串来执行以下操作:
$image = "Image One Here";
$title = "Title One Here";
$link = "Link One Here";
$image = "Image Two Here";
$title = "Title Two Here";
$link = "Link Two Here";
$image = "Image Three Here";
$title = "Title Three Here";
$link = "Link Three Here";
foreach(condition here) {
echo $image;
echo '<br/>';
echo $title;
echo '<br/>';
echo $link;
}
有关如何实现这一目标的任何想法?提前谢谢!
答案 0 :(得分:3)
这样你就可以做到。
$image[] = array('Image one here','Image two here');
$title[] = array("Title One Here","Title Two Here");
$link[] = array("Link One Here","Link Two Here");
foreach($image as $value)
{
echo $image[$value];
echo $title[$value];
echo $link[$value];
}
答案 1 :(得分:1)
希望它有所帮助,
$image[] = "Image One Here";
$title[] = "Title One Here";
$link[] = "Link One Here";
$image[] = "Image Two Here";
$title[] = "Title Two Here";
$link[] = "Link Two Here";
$image[] = "Image Three Here";
$title[] = "Title Three Here";
$link[] = "Link Three Here";
foreach($image as $key=>$img) {
echo $img;
echo '<br/>';
echo $title[$key];
echo '<br/>';
echo $link[$key];
}
答案 2 :(得分:1)
以下是for
和foreach
$images = array('image1','image2','image3');
$titles = array('title','title2','title3');
$links = array('link1','link2','link3');
for($i=0; $i<count($images);$i++){
echo $images[i]. "<br/>" . $titles[i] . "<br/>" . $links[i]."</br>";
}
或使用foreach()
foreach($images as $key => $value){
echo $images[$key]. "<br/>" . $titles[$key] . "<br/>" . $links[$key]."</br>";
}
答案 3 :(得分:1)
尝试使用数组
$image=array('One','Two','Three');
$link=array('One','Two','Three');
$title=array('One','Two','Three');
foreach($title as $key)
{
echo $image[$key].'<br/>';
echo $link[$key].'<br/>';
echo $title[$key].'<br/>';
}
简单