The code defines an anonymous function that returns the expected result.
Nothing special here...
fn($A$R){$X=[]each$R as$k=>$v;if$v$X=&array_concat($X&array_fill($A[$k]$v))send$X;}
Usage
Just use it normally...
Example using the 2nd test case.
$fn = fn($A$R){$X=[]each$R as$k=>$v;if$v$X=&array_concat($X&array_fill($A[$k]$v))send$X;}
// should output: 6,6,6,6,6,0,0
echo &join(call $fn([6,0,0,6], [5,1,1,0]), ',');
Since it is an anonymous function, using call is required.
Ungolfed
This code does exactly the same as the golfed version.
This is pretty close to pseudo-code.
Set $fn to an anonymous function($A, $R)
Begin.
Define the variable $result = [].
Loop through $R as value $value key $key.
Begin.
If $value then.
Begin.
Set $result to the result of calling &array_concat(
$result,
&array_fill($A[$key], $value)
).
End.
End.
Return the $result.
End.
A little further from pseudo-code...
$fn = fn($A, $R) => {
$result = [];
foreach $R as $key => $value {
if $value {
$result = &array_concat(
$result,
&array_fill($A[$key], $value)
);
}
}
return $result;
};