Answer the question
In order to leave comments, you need to log in
Is it possible to create a function like array_combine in php?
There is an array - $arr = array(1,2,3);
And you need to make these values become keys, and then add more arrays to these keys.
I don't know why, but I was wondering how to create an array_combine with my own hands.
Answer the question
In order to leave comments, you need to log in
function my_array_combine(array $keys, array $values) {
if (count($keys) !== count($values)) throw new \InvalidArgumentException();
$keys = array_values($keys);
$values = array_values($values);
$result = [];
for($i = 0;$i<count($keys);$i++) {
$result[$keys[$i]] = $values[$i];
}
return $result;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question