Jump to content

[SOLVED] how would i do this?


yami007

Recommended Posts

this is my code

<?php
$q1 = 'hello';
$q2 = 'Hi';
$q3 = 'Hey';
$q4 = 'Bye';
$q5 = 'See you';

$i = 0;
while ($i <= 4) {
	$i++;
	$
	echo 'Greetings : '.$q.$i.'<br />';	
}
?>

 

what i want to is get the variable $i before getting the variable $q so that it would display something like :

 

Greetings : hello

Greetings : hi

Greetings : hey

...

 

how ??

Link to comment
https://forums.phpfreaks.com/topic/175028-solved-how-would-i-do-this/
Share on other sites

Use an array any time you have a set of related variables that you need to access -

<?php
$q[1] = 'hello';
$q[2] = 'Hi';
$q[3] = 'Hey';
$q[4] = 'Bye';
$q[5] = 'See you';

$i = 0;
   while ($i <= 4) {
      $i++;
      echo 'Greetings : '.$q[$i].'<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.