0

hello,

i want to arrange variables in array from foreach loop like this

foreach($arr as $array){

$variable['first']      = $array['im'];  //first record from im column in a table  
$variable['second']= $array['im']; //2nd record from im column in a table  
}
echo $variable['first'];
echo $variable['second'];

the purpose is to make the variable available outside the loop without looping. any idea please....

Edited by servis: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by servis
0

i dont really understand. Couldnt you just use

$arr[0] or $arr[1]

to get the variable?

0

actually, the full code is just like that,

$sql = "SELECT img_id, img_thumbnail FROM images WHERE img_id = 15";
$result = mysql_query($sql) or die ('list fail' .  sql_erroe());
while($row = mysql_fetch_array($result)){
$arr[]=$row;
}

foreach($arr as $array){

$param['image1] = $array['img_thumbnail'];  //first image thumbnail  from image column in a mysql table  
$param['image2'] = $array['img_thumbnail']; //2nd image thumbnail from image column in a mysql table  
}
echo $param['image1'];
echo $param['image2'];

hope the above code will clear the requirement..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.