php - Combine 2 arrays into a third array with inconstant unique keys from one array
I have 2 arrays as below.
$keys = [1,2,3,4-1,99,1,2,3,4-1,4-2,4-3,99,1,2,3,4-1,4-2,99] $values = [a,b,c,d,x,a1,b1,c1,d1,e,g,x,a2,b2,c2,d2,e,x]
I want to combine into an array like:
$result = array( =>array(1=>a,2=>b,3=>c,4-1=>d,99=>x), =>array(1=>a1,2=>b1,3=>c1,4-1=>d1,4-2=>e,4-3=>g,99=>x), =>array(1=>a2,2=>b2,3=>c2,4-1=>d2,4-2=>e,99=>x );
The rule is break anytime $key=99. Currently, I tried to use array_chunk but the syntax only allows me to chunk the array by the number of unique keys, which is not constant in my example. Any advice?