Here's something I quickly whipped up on the command line using PHP functions. I'd suggest that you convert the array into a collection and use the methods that collections have available to them.
I also use array_filter to remove null values. Be aware that the array keys are removed as well so you may also need to run it through array_merge() to fix the indexes. JavaScript for instance would see it as an object and no longer as array
Rather than test every value in each item, is there a required field that you can test so that if that is null then it does not matter if the other values are set (or its impossible that they will be).
@knubbe82 you would've been better to start working with me than you've decided to stay at your current job :P
Also tell Max to hire me as a consultant :D
It is nice to see you here @knubbe82
Best regards.
@knubbe82 Be aware that the best answer will not work if one of the values is an empty sting instead of null. Just in case that could happen :) If not, its a very good and clean solution :)
@sinnbeck but he did not ask for a solution where one of the values is an empty string. There are many solutions. This is one for his example that he asked for.
@bugsysha True. And your solution is elegant and the best answer. I'm simply trying to be nice and give him a heads up if that could end up being an issue 😊 "remove empty values" could mean different things
@sinnbeck I think that he just needs a general guideline and not specific solution. Most of the users here just present simplified problems in which way they try to protect the data they are working with or something like that.
If we have to think about all possibilities that might occur, our heads would grow exponentially and they would have to give us a chunk of their salary :D