Jump to content

Recommended Posts

Hello guys,

 

I hope I can explain this clearly. I have a number of variables that are created inside a loop containing results from mysql_fetch_array:

 

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

$EUR[$i] = $row['EUR'];
$USD[$i] = $row['USD'];
$AUD[$i] = $row['AUD'];
$NZD[$i] = $row['NZD'];
$CAD[$i] = $row['CAD'];
}

 

So I can now call any particular value by echoing say "$EUR[2]" or "$USD[5]".

 

Next I have two variables that are created using $_GET - $currency - which can be "EUR", "USD", "AUD" etc. and $delivery_period - which can be 1, 2, 3 etc.

 

What I would like to be able to do is concatenate $currency and $delivery_period to form $EUR[3] or $USD[1] etc. so I can actually echo the value in the corresponding array on-screen. My PHP skills aren't that strong and I was told the solution maybe used eval() but I can't get anything to work. Any help would be greatly appreciated :)

Just use one array -

<?php
$arr = array();
for ($i=1; $i<=7; $i++) {
$row = mysql_fetch_array($result);
$arr['EUR'][$i] = $row['EUR'];
$arr['USD'][$i] = $row['USD'];
$arr['AUD'][$i] = $row['AUD'];
$arr['NZD'][$i] = $row['NZD'];
$arr['CAD'][$i] = $row['CAD'];
}

$currency = 'EUR';
$delivery_period  = 3;

echo $arr[$currency][$delivery_period]; // $arr['EUR'][3]
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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