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....

i dont really understand. Couldnt you just use

$arr[0] or $arr[1]

to get the variable?

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..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.