这是我的代码:
foreach ($states as $staterow) {
$state_set[] = array ('id' =>$staterow['id'],
'st' =>$staterow['st'],
'state' =>$staterow['state']);
}
foreach ($showresult as $display) {
$display_result[] = array ( 'id' => $display['id'],
'name' => $display['name'],
'club_email' => $display['club_email'],
'description' => $display['description'],
'city' => $display['city'],
'state' => $display['state'],
'url' => $display['url'],
'facebook' => $display['facebook']);
unset($dispay_result);
$statearray[] = array ( 'state' => $display['state'] );
}
foreach ($statearray as $display) {
$letterprocess[] = substr($display['state'], 0, 1);
}
foreach ($fulllist as $x => $x_value) {
foreach ($letterprocess as $y => $y_value) {
IF ($x_value == $y_value) {
$true[] = array ($x_value);
}
}
}
var_dump($true);
为什么$true是一个多维数组?为什么它不作为一个简单的数组出现呢。如果我在循环中回显$x_value,它是一个变量,而不是数组。
这是var_dump:
array(12) {
[0]=> array(1) {
[0]=> string(1) "A"
}
[1]=> array(1) {
[0]=> string(1) "C"
}
[2]=> array(1) {
[0]=> string(1) "C"
}
[3]=> array(1) {
[0]=> string(1) "I"
}
[4]=> array(1) {
[0]=> string(1) "I"
}
[5]=> array(1) {
[0]=> string(1) "M"
}
[6]=> array(1) {
[0]=> string(1) "M"
}
[7]=> array(1) {
[0]=> string(1) "M"
}
[8]=> array(1) {
[0]=> string(1) "M"
}
[9]=> array(1) {
[0]=> string(1) "M"
}
[10]=> array(1) {
[0]=> string(1) "N"
}
[11]=> array(1) {
[0]=> string(1) "V"
}
}
$true[] = $x_value;
就是你想要的。
在使用时
$true[] = array ($x_value);
显式地将$x_value
强制转换为一个数组(array ($x_value)
),然后将该数组添加到$true
数组中,为自己提供一个数组数组