Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
创建&;从foreach引用PHP变量进行比较_Php_Json_Api_Trello - Fatal编程技术网

创建&;从foreach引用PHP变量进行比较

创建&;从foreach引用PHP变量进行比较,php,json,api,trello,Php,Json,Api,Trello,我的目标是根据第二个UL中出现的列表,对每个列表项应用一个特定的类。第二个json调用返回与第一个列表中的ID和名称对匹配的ID 我希望将每个listID分配给一个名为$listID的$variable,其值就是该列表的名称 例如,$514FC8993F53CFB36606851=“待办事项” 然后,我可以使用if语句根据PHP第二块中的一系列if语句分配一个类 如果您能帮助生成这些变量,我们将不胜感激 有关守则如下: <p>The sample board contains the

我的目标是根据第二个UL中出现的列表,对每个列表项应用一个特定的类。第二个json调用返回与第一个列表中的ID和名称对匹配的ID

我希望将每个listID分配给一个名为$listID的$variable,其值就是该列表的名称

例如,$514FC8993F53CFB36606851=“待办事项”

然后,我可以使用if语句根据PHP第二块中的一系列if语句分配一个类

如果您能帮助生成这些变量,我们将不胜感激

有关守则如下:

<p>The sample board contains the following lists:</p>
<ul>
    <?
        $lists_enc = file_get_contents("https://api.trello.com/1/board/".$BOARD."/lists?key=9ee57574e9f968cedf9ac9964d2f7c4e");
        $lists = json_decode($lists_enc, true);
        $testing = array();

        foreach ($lists as $list) {
            $id = $list["id"];
            $name = $list["name"];

            echo "<li>".$name." (".$id.")</li>\n";
        }
        echo "</ul>";
    ?>

<p>The sample board contains the following cards:</p>
<ul>
    <?
        $cards_enc = file_get_contents("https://api.trello.com/1/board/".$BOARD."/cards?fields=name,idList&key=9ee57574e9f968cedf9ac9964d2f7c4e");      
        $cards = json_decode($cards_enc, true);

        foreach ($cards as $card) {
        echo "<li class=".$status.">".$card["name"]."</li>\n";
      }  

    ?>
</ul>
样本板包含以下列表:

    样本板包含以下卡片:



请原谅我拙劣的解释。我希望每个页面ID都有一个单独的变量,以提供页面名称。最终采用了一个稍微不同的解决方案,但您的建议帮助我解决了这个问题,所以谢谢。目标是使用此json创建3个变量-这允许我转换ID(包含在另一个json输出中)到名称(仅在此json输出中)做得好!为什么在第一个循环中使用($i=0…)的格式而不是foreach()?
<?php
//Reference the trello API's
$lists_enc = file_get_contents("https://api.trello.com/1/board/".$BOARD."/lists?key=9ee57574e9f968cedf9ac9964d2f7c4e");
$lists = json_decode($lists_enc, true);
$cards_enc = file_get_contents("https://api.trello.com/1/board/".$BOARD."/cards?fields=name,idList&key=9ee57574e9f968cedf9ac9964d2f7c4e");      
$cards = json_decode($cards_enc, true);
//Go through every card
foreach ($cards as $card) {
    $idCard = $card['id'];

    //Go through all lists
    foreach ($lists as $list) {
        $idList = $list['id'];

        //If card is related to list, then create an associative variable
        //with the id of list
        if ($card['id'] == $list['id'] {
            $idList[$idList][] = $idCard;
        }
    }
    //gone through all lists
}
//-- gone through all cards
?>
<?
  // Create array $convert[] to allow translation of listID into listName
    for ($i=0; $i < count($lists); $i++) { 
      $convert[$lists[$i][id]]=$lists[$i][name];
    }

  // iterate over all cards, create list item for each with class that has a slug equivalent of the list name  
    foreach ($cards as $card) {
       $id = $card[idList];
       echo "<li class=".slug($convert[$id]).">".$card["name"]."</li>\n";
    }  

?>