I'm starting a magazine which has 3 editions. UK, US, and European. Each will be published online at different times, therefore each has a different issue number.
So I want to create a way of selecting which issue goes with which edition, but I don't know how to join these 2 parts together. The code I'm using is:
<?php
$this_edition = "UK";
?>
<?php
$UK_issue = "1";
$US_issue = "3";
$EU_issue = "2";
?>
<?php
$this_issue = // The Issue Relating to This Edition
?>
What I want to do here is basically call the issue number ( 1/3/2 ) which relates to the $edition
I'm udating, in this case, UK.
So essentially : $this_issue = $edition_issue
Does anyone know how I can do this?
What you're trying to do is possible...
$this_issue = ${$this_edition.'_issue'};
But it's way better to use the solution suggested by pr1nc3.
How about an array so you have keys
and values
to match?
For example $magazine = [1 => 'UK', 2 => 'US', 3 => 'EU'];
Array
(
[1] => UK
[2] => US
[3] => EU
)
Your array keys (issues) match the country(edition)
You may use Associative Array as shown below.
<?php
$this_edition = "UK";
$edition['UK'] = 1;
$edition['US'] = 2;
$edition['EU'] = 3;
$this_issue = $edition[$this_edition];
?>
How about an array so you have keys and values to match?
$magazine = array(1 => 'UK', 2 => 'US', 3 => 'EU');
$issue=1;
echo $magazine[$issue];
output will be
UK
I think you have already got your answer, But just want to show you another way if you need to hold more details about your editions and issues in an array.
<?php
$this_edition = "UK";
$editions = array("UK"=>array("name"=>"UK Edition","value"=>1), "US"=>array("name"=>"US Edition","value"=>2), "EU"=>array("name"=>"EU Edition","value"=>3));
echo $this_issue = $editions[$this_edition]["name"];
?>
Output: UK Edition
If you keep your information inside mapped array, you will be able to receive them very easily at any point you need.