我正在尝试运行阵列组合,但由于两个数组之间存在不同的值,因此这两个数组是$ keys和$ value,$ value包含城市“Presidente Prudente”和“São”保罗“状态在两个不同的位置,当它应该只在一个位置。例如“Presidente Prudente - SãoPaulo”这个类用于各种其他和不同的未来价值,这只发生在城市和州
下面的var_dump $键,在$ keys变量中,字段“cidade”表示City
array
0 => string 'Make' (length=4)
1 => string 'Model' (length=5)
array
0 => string 'cidade' (length=6)
var_dump $ value:
array
0 => string 'BMW' (length=3)
1 => string 'X6' (length=2)
array
0 => string 'São Paulo' (length=10)
1 => string 'Presidente Prudente' (length=19)
我目前的课程:
public function __construct($propertyId, $levelIds, $value, $treeDepth = null)
{
$this->propertyId = $propertyId;
$keys = explode("," , $levelIds);
$keys = array_map("trim", $keys);
while (count($value) < count($keys))
$value[] = null;
$this->value = array_combine($keys, $value);
$this->treeDepth = $treeDepth;
}
错误:
(!)警告:array_combine()[function.array-combine]:两个参数在C:\ wamp \ www \ carros \ system \ lib \ orm \ types \ TreeType.php中应该具有相同数量的元素第264行
答案 0 :(得分:0)
您已经知道array_combine
在两个数组(键和值)中需要相同数量的元素才能匹配它们,对吗?
这是一个例子:
$keys = array('city','country');
$values = array('São Paulo','Brazil');
print_r(array_combine($keys,$values));
/*
Array
(
[city] => São Paulo
[country] => Brazil
)
*/