在php中将一个数组的第0个索引与第0个索引结合起来另一个数组

I am new to PHP. and I want to combine two arrays from 0th index e.g.

$a = [7, 5, 6, 9]
$b = [1, 3, 2, 4]

result should be

$c = ["7-1", "5-3", "6-2", "9-4"];

You can use a simple foreach loop, and put them together. This of course expects that there are at least as many elements in $b as there are in $a.

$a = [7, 5, 6, 9];
$b = [1, 3, 2, 4];
$result = [];

foreach ($a as $key=>$value) {
    $result[] = $value.'-'$b[$key];
}

If for some reason your array isn't numerically indexed, you can use array_values() to extract the values only (thus getting a numerically indexed array).

If you expect that $b can be shorter than $a, you can stop at the last iteration of $b by checking if that element exists by doing..

$a = [7, 5, 6, 9];
$b = [1, 3, 2, 4];
$result = [];

foreach ($a as $key=>$value) {
    if (!isset($b[$key])) {
        break;
    }
    $result[] = $value.'-'$b[$key];
}

You can use one-liner,

$result = array_map(function($a1,$b1){ return $a1.'-'.$b1; },$a,$b);

array_map accept multiple arrays and simultaneously we can receive instance of each one.

Demo.

You can use array_combine with array_walk

$c = array_combine($a,$b);
$r = [];
array_walk($c, function($k,$v) use (&$r){$r[] = "{$v}-{$k}";});
print_r($r);

DEMO