【发布时间】:2014-05-15 03:58:30
【问题描述】:
这个语法在php中是什么意思
foreach ( $meta as $t => $data )
上面的 $t => $data 是什么意思。
因为 foreach 基本上是(来自 w3school 的示例)
<?php
$colors = array("red","green","blue","yellow");
foreach ($colors as $value)
{
echo "$value <br>";
}
?>
上面的例子$value代表$t => $data
$colors代表$meta
数组$meta如下
$meta = Array(
'facebook' => Array(
'title' => 'og:title',
'type' => 'og:type',
'url' => 'og:url',
'thumbnail' => 'og:image',
'width' => 'og:image:width',
'height' => 'og:image:height',
'sitename' => 'og:site_name',
'key' => 'fb:admins',
'description' => 'og:description'
),
'twitter' => Array(
'card' => 'twitter:card',
'description' => 'twitter:description',
)
);
那么什么是$t,什么是$data
如果我想在 'facebook' 中获取 'title' 作为单独的键,该怎么做。 IE。会
$t => $data => $final work
$t = facebook or twitter
$data = title etc
$final = og:title etc
【问题讨论】:
-
$t => $data 表示像数组 $key=>$value
-
$t代表数组的键。阅读manual了解更多详情。 -
不大于等于符号
-
@SanthoshYedidi - 不。它有不同的含义。
-
坦率地说,你最好找个地方other 比 w3schools 学习 PHP。实际的PHP manual 非常有用;它包含几乎所有内容的示例,包括
foreach