Given an array like
$x = array(array('a', 'aa'), array('b', 'bb'), array('c', 'cc'));
There is array_column that returns either
array_column($x, 0) === array('a', 'b', 'c')
or
array_column($x, 1) === array('aa', 'bb', 'cc')
Now, is there an inverse? A function that would do:
array_putoneaftertheother(array('a', 'b', 'c'), array('aa', 'bb', 'cc')) === array(array('a', 'aa'), array('b', 'bb'), array('c', 'cc'))
None come to my mind...
It's pretty easy to implement, but I'm surprised that with so many array_* functions, PHP has no native version of this?!
array_column().array_column()returns a "vertical slice". Inverse/opposite of this would be a horizontal slice (or maybe everything except that column, but let's not go there), which is just$x[n]. What you described seems like rotating a 2D array, so rows become columns and columns become rows.array_column(array_putoneaftertheother($x, $y), 0) === $xso likef • g = Idmeaningffunction isginverse. Opposite would bef•g=0Tho you may indeed consider this as atransposefunction of thearray('a','b','c')vector