我得到两个数组
Array
(
[0] => 1990
[1] => 1991
[2] => 1992
[3] => 1993
[4] => 1994
[5] => 1995
[6] => 1996
[7] => 1997
[8] => 1998
[9] => 1999
[10] => 2000
[11] => 2001
[12] => 2002
[13] => 2003
[14] => 2004
[15] => 2005
[16] => 2006
[17] => 2007
[18] => 2008
[19] => 2009
[20] => 2010
[21] => 2011
[22] => 2012
[23] => 2013
)
和
Array
(
[0] => Array
(
[year] => 2011
[conv_value] => 80
)
[1] => Array
(
[year] => 2012
[conv_value] => 95
)
[2] => Array
(
[year] => 2004
[conv_value] => 60
)
[3] => Array
(
[year] => 2000
[conv_value] => 55
)
)
并希望从第一个数组中的第二个数组中找到年份的匹配项并创建一个长度正好为第一个数组搜索的新数组应该如下所示:
如果找到年份,则将设置一个新索引名称conv_value包含来自第二个数组索引conv_value的值,如果未找到,则conv_value将为空。
像这样
Array
(
[0] => Array
(
[year] => 1990
[conv_value] =>
)
[1] => Array
(
[year] => 1991
[conv_value] =>
)
[2] => Array
(
[year] => 1992
[conv_value] =>
)
[3] => Array
(
[year] => 1993
[conv_value] =>
)
[4] => Array
(
[year] => 1995
[conv_value] =>
)
[5] => Array
(
[year] => 1996
[conv_value] =>
)
[6] => Array
(
[year] => 1997
[conv_value] =>
)
[7] => Array
(
[year] => 1998
[conv_value] =>
)
[8] => Array
(
[year] => 1999
[conv_value] =>
)
[9] => Array
(
[year] => 2000
[conv_value] => 55
)
[10] => Array
(
[year] => 2001
[conv_value] =>
)
[11] => Array
(
[year] => 2002
[conv_value] =>
)
[12] => Array
(
[year] => 2003
[conv_value] =>
)
[13] => Array
(
[year] => 2004
[conv_value] => 95
)
[14] => Array
(
[year] => 2005
[conv_value] =>
)
[15] => Array
(
[year] => 2006
[conv_value] =>
)
[16] => Array
(
[year] => 2007
[conv_value] =>
)
[17] => Array
(
[year] => 2008
[conv_value] =>
)
[18] => Array
(
[year] => 2009
[conv_value] =>
)
[19] => Array
(
[year] => 2010
[conv_value] =>
)
[20] => Array
(
[year] => 2011
[conv_value] => 80
)
[21] => Array
(
[year] => 2012
[conv_value] => 95
)
[22] => Array
(
[year] => 2013
[conv_value] =>
)
)
我编写了脚本
for ( $y = 0; $y < sizeof($cc); $y++ ){
for ( $z = 0; $z < sizeof($years); $z++ ){
if ($cc[$y]['year'] == $years[$z]) {
echo 'Hay<br>';
}else{
echo 'Nahee hay<br>';
}
}
}
但没有得到结果..
我在哪里做错了。?