Jump to content

[SOLVED] how to loop this method thank u


redarrow

Recommended Posts

Advance thank u......

 

 

How can i use a loop to get the same results tried a for loop and foreach how please..........

<?php

$x=array(
    "title1"=>"Theme Song Heroes" ,  "song1"=>"We happily sing your theme songs." , "name1"=> " Mythbusters"
,  "title2"=>"Theme Song Heroes" , "song2"=> "We happily sing your theme songs." ,  "name2"=>" Batman "
,  "title3"=>"Theme Song Heroes" , "song3"=>"We happily sing your theme songs." ,   "name3"=>" Power Rangers"
  , "title4"=>"Theme Song Heroes" ,  "song4"=>"We happily sing your theme songs." ,  "name4"=>" Dirty Jobs"
  , "title5"=>"Ice Cream" ,  "song5"=>"Plays that ice cream truck jingle." ,  "name5"=>" We all scream"
  , "title6"=>"Ice Cream" , "song6"=>"Plays that ice cream truck jingle." , "name6"=> "Ice ice cream"
);		

echo " Title:$x[title1] <br> Song:$x[song1] <br> Name$x[name1]<br><br>
Title:$x[title2] <br> Song:$x[song2] <br> Name$x[name2]<br><br>
Title:$x[title3] <br> Song:$x[song3] <br> Name$x[name3]<br><br>
Title:$x[title4] <br> Song:$x[song4] <br> Name$x[name4]<br><br>
Title:$x[title5] <br> Song:$x[song5] <br> name:$x[name5]<br><br>
Title:$x[title6] <br> Song:$x[song6] <br> Name:$x[name6]<br><br>";

?>

Link to comment
https://forums.phpfreaks.com/topic/126404-solved-how-to-loop-this-method-thank-u/
Share on other sites

SOLVED MY SELF

 

<?php
$x=array(
    "title1"=>"Theme Song Heroes" ,  "song1"=>"We happily sing your theme songs." , "name1"=> " Mythbusters"
,  "title2"=>"Theme Song Heroes" , "song2"=> "We happily sing your theme songs." ,  "name2"=>" Batman "
,  "title3"=>"Theme Song Heroes" , "song3"=>"We happily sing your theme songs." ,   "name3"=>" Power Rangers"
  , "title4"=>"Theme Song Heroes" ,  "song4"=>"We happily sing your theme songs." ,  "name4"=>" Dirty Jobs"
  , "title5"=>"Ice Cream" ,  "song5"=>"Plays that ice cream truck jingle." ,  "name5"=>" We all scream"
  , "title6"=>"Ice Cream" , "song6"=>"Plays that ice cream truck jingle." , "name6"=> "Ice ice cream"
);		

for($i=1; $i<7; $i++){

	$title=$x[title.$i];
	$song=$x[song.$i];
	$name=$x[name.$i];

echo " Title:$title <br> Song:$song <br> Name:$name<br><br>";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.