Question

It's a simple question, but searching here I found different variations, but not really what I need. So:

Say I have array of numbers: [1,4,5,7,9] What I need is an inverted result set of numbers up to max 10: [2,3,6,8,10]

Was it helpful?

Solution

$initialArray = array(1,4,5,7,9);
$requiredRange = range(1,10);

$invertedArray = array_diff($requiredRange,$initialArray);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top