[英]Generate a dynamic switch structure in PHP
Is there a way you can create a dynamic generated switch statement? 有没有办法创建动态生成的switch语句? I will explain further, I have a table with all the possible coins.
我将进一步解释,我有一张桌子,上面有所有可能的硬币。 Every person has a table with their own coins.
每个人都有一张桌子,上面有自己的硬币。 If you click on a coin a new action will happen in the php and you will be direct for example to
index.php?actie=Ripple
. 如果您单击硬币,则php中将发生新动作,您将直接进入
index.php?actie=Ripple
。
My code: 我的代码:
case "Ripple":
if ($_SESSION["name"] == "d"){
$dataFromTransactions = $pol->toonAllesD("XRP/BTC");
}
else{
$dataFromTransactions = $pol->toonAlles("XRP/BTC");
}
Uitvoer::toonDeRippleTable($dataFromTransactions,"Ripple");
break;
case "LiteCoin":
if ($_SESSION["name"] == "d"){
$dataFromTransactions = $pol->toonAllesD("LTC/BTC");
}
else{
$dataFromTransactions = $pol->toonAlles("LTC/BTC");
}
Uitvoer::toonDeRippleTable($dataFromTransactions,"LiteCoin");
break;
Is there a way that I need to do like a: 有没有一种我需要做的方法:
$alleCoins = $pol->getAlleCoinsYouBuyed()
foreach($alleCoins as $coinInfo){
case $coinInfo->Coinname :
if ($_SESSION["name"] == "d"){
$dataFromTransactions = $pol->toonAllesD($coinInfo->Market);
}
else{
$dataFromTransactions = $pol->toonAlles($coinInfo->Market);
}
Uitvoer::toonDeRippleTable($dataFromTransactions,$coinInfo->Coinname);
break;
}
this code must be in the index.php 此代码必须在index.php中
This is the solution 这是解决方案
if ($_SESSION["name"] == "d"){
$alleCoins = dataBaseTrade::getPoloniexInstantie()->getAlleCoinsYouBuyedD();
}
else {
$alleCoins = dataBaseTrade::getPoloniexInstantie()->getAlleCoinsYouBuyed();
}
$searchNameArray = json_decode(json_encode($alleCoins), true);
$searchNameArray = array_column($searchNameArray, "Coinname" );
switch ($actie){
case ($actie != "home" || "user"):
$valueOfThePlaceInTheArray = array_search($actie,$searchNameArray);
$thisCoin = $alleCoins[$valueOfThePlaceInTheArray];
if ($_SESSION["name"] == "d"){
$dataFromTransactions = $pol->toonAllesD($thisCoin->Market);
}
else{
$dataFromTransactions = $pol->toonAlles($thisCoin->Market);
}
Uitvoer::toonDeRippleTable($dataFromTransactions,$thisCoin->Coinname);
break;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.