【问题标题】:Print data from array php从数组php打印数据
【发布时间】:2014-02-14 21:23:38
【问题描述】:

对不起,菜鸟问题,但是,我如何从数组中打印 cid1 和 cid2 的值?

这里有简单的代码:

// Handle the parsing of the _ga cookie or setting it to a unique identifier
function gaParseCookie() {
  if (isset($_COOKIE['_ga'])) {
    list($version,$domainDepth, $cid1, $cid2) = split('[\.]', $_COOKIE["_ga"],4);
    $contents = array('version' => $version, 'domainDepth' => $domainDepth, 'cid' => $cid1.'.'.$cid2);
    $cid = $contents['cid'];
  }
  else $cid = gaGenUUID();
  return $cid;
}


echo "Welcome " . $contents['cid1'] . "!<br>";

【问题讨论】:

  • 你试过print_r功能吗? us1.php.net/print_r
  • ^ 或 foreach 循环也可以。
  • 我不明白我必须在 print_r 中插入哪些参数。你能写出来,它应该是什么样子的吗?
  • @КонстантинРусанов:首先阅读 txtechhelp 给你的链接。
  • 只是我还是 $content 没有索引 cid1?我只看到它有一个 cid 索引 - 它将 cid1 与 cid2 连接起来

标签: php arrays cookies echo


【解决方案1】:

"$contents" 在本地范围内。你必须写这样的东西echo "Welcome " . gaParseCookie() . "!&lt;br&gt;"; 因为“gaParseCookie”函数会返回你需要的值。

【讨论】:

    【解决方案2】:

    应该这样做

    print_r(gaParseCookie());
    

    【讨论】:

      【解决方案3】:

      如果我没看错你的问题,这就是我认为你想要的。

          function gaParseCookie() {
            if (isset($_COOKIE['_ga'])) {
              list($version,$domainDepth, $cid1, $cid2) = split('[\.]', $_COOKIE["_ga"],4);
              $contents = array('version' => $version, 'domainDepth' => $domainDepth, 'cid' => $cid1.'.'.$cid2);
              $cid = $contents['cid'];
              echo "Welcome " . $cid1 . "!<br>";
            }
            else $cid = gaGenUUID();
            return $cid;
          }
      

      $content[] 中没有 cid1 索引。如果您想要 $cid1 变量中的值,您需要在该函数中调用它。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-07-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多