If I’m understanding, what the problem is was answered to your earlier asking.
While I agree that sorting the numbers would make it easier to manually spot “wrong” numbers, unless this is only to make it easier to debug the script I don’t see this approach as being anything easily maintainable. IMHO it would be much better to tighten up the code and have unit tests keep an eye on it.
As benanamen is implying, the better approach would be to figure out where the “wrong” number is coming from and how it’s getting included with the “right” numbers.
We are “maybe” dealing with a DB query or “maybe” dealing with an if clause. OP is talking about “wrong numbers”. What is a “wrong number”? Why is OP “scanning” for them with his eyes? He says variables can be “jumbbled” or “arranged”. What does that mean? OP shows a max of two numbers but says “jumbleVar is sometimes very long”. What is a “jumbleVar”? OP also says “It cannot,actually, be short to write about the overall task.”
So I submit, the OP clearly has not told us what the REAL problem is which is why every response is just guessing at what an answer might be to his attempted solution.
I really want talk with you about my coding story since people don’t listen to it around me.
I don’t know I have to tell from where to where.
I will be happy to talk with you about my long story and I like, if you don’t mind, to listen to your story.
I am sorry you are out.
Have a good day, and see you.
The result of the above code is “OR var25”.
I write the following code for changing my original variable “$jumbleVar” into array pattern.
The result of the above is the following,
The above result is the same as the jumble array data.
echo $jumble; is “OR var25”, but echo $jumble2 is the following.
How can I make it jumble2 is “OR var25” instead of ‘OR var=25", “OR var=8”, “OR var=17”, "OR var=3’.?
I have, I think, to make the variable “$jumbleVar” into an array for sorting it.
We have established that this is part of a database query.
So as mentioned it would be better to use an IN condition instead of a long chain of OR conditions.
This will also make sorting the data easier.
$numbers = array(8, 3, 25, 17); // Starting with an array of numbers in unsorted order
sort($numbers); // This will sort the number into order
$inlist = implode(', ', $numbers); // Turns the array into a string of CSV
var_dump($inlist); // This will allow you to manually check the numbers on screen
$query = "SELECT * FROM table WHERE var IN ($inlist)"; // Create the query string with the list of values
Just a note of caution here. There may be a potential danger of injection putting the variable into the query if you are not 100% certain all values will be integers. If you do not have absolute control over where these values come from it will need a slightly different approach for the query, but that is going a little off topic for the current problem.