array_combine - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of array_combine.php
- <?php
- function c($h, $a) {
- $r = [];
- foreach($a as $i => $v) {
- $k = $h[$i] ?? false;
- if ($k !== false) {
- $r[$k] = $v;
- } else {
- $r[] = $v;
- }
- }
- return array_pad($r, count($h), null);
- }
- $h = ['a', 'b', 'c'];
- $row = [4,3,2,1];
- var_dump(c($h,$row));
- $add = array_splice($row, count($h));
- $res = array_combine($h, array_pad($row, count($h), null)) + $add;
- var_dump($res);
- $h = ['a', 'b', 'c'];
- $row = [4,3,2];
- var_dump(c($h,$row));
- $add = array_splice($row, count($h));
- $res = array_combine($h, array_pad($row, count($h), null)) + $add;
- var_dump($res);
- $h = ['a', 'b', 'c'];
- $row = [4,3];
- var_dump(c($h,$row));
- $add = array_splice($row, count($h));
- $res = array_combine($h, array_pad($row, count($h), null)) + $add;
- var_dump($res);
File Description
- array_combine
- PHP Code
- 21 Jun-2019
- 805 Bytes
You can Share it:
Latest PHP Pastes