如果给定一个关联数组而不是普通数组,我希望一个PHP函数在不改变函数签名的情况下表现得不同。
注意:您可以假设数组是同质的。例如,array(1,2,"foo" => "bar")
是不被接受的,可以忽略。
function my_func(Array $foo){
if (…) {
echo "Found associated array";
}
else {
echo "Found regular array";
}
}
my_func(array("foo" => "bar", "hello" => "world"));
# => "Found associated array"
my_func(array(1,2,3,4));
# => "Found regular array"
PHP可以实现这个吗?
array(1, 2, 'foo' => 'bar', 3, 4, 'hello' => 'world')
)? - BoltClock