Php sorting?

Dj_Jestar said:
On a side note re: reiterative use of count() - it actually references the hashes integer that is only updated when you create, add an item, or remove an item from the array (the engine stores arrays as a hash in memory)

So the difference is a lot smaller than you think, because count() doesn't 'count'

iirc it actually has 2 function calls, one of those being a function fork.
Will this affect functionality?

Also, has anyone any idea for post #17? :(
 
jdickerson said:
I want to check the value of I (tab seperated numbers - e.g. 1 2 3 4 5) against J. I want to then output any DIFFERENCES found.

I.e. I = 1 2 3 4 5, J = 4 5 6 7 8. OUTPUT would be = 4 5.

Aren't those the matches rather than the differences (1, 2, 3, 7, 8)?

Which do you want?
 
Explode them into arrays, then use array_intersect to find the values that are present in both arrays or array_diff to find the ones that are only in one.

Code:
$one = "1	2	3	4	5";
$two = "3	4";

$one = explode("\t", $one);
$two = explode("\t", $two);

$same = array_intersect($one, $two); // returns array(4, 5)
$different = array_diff($one, $two); // returns array(1, 2, 3)
 
null said:
Sorry, if I'd known it was convention I wouldn't have argued :o Will remember that in future, thanks :)

null :)
i'm sure i read in the past that some languages have had issues with numbers in var names, perhaps more so where a var's data is a number. i think to be extra safe a lot of folk got into a habit of avoiding using numbers in vars name full stop.

so i don't think people are just being fussy with this i1/i2 stuff, use iA, iB if doing such makes it easier for you to read.. not everyone uses i, j because j is just an i with a tail. i've seen a lot of folk over the years skip j and use i, k much like the army skip five during countdowns.
 
Hector said:
i'm sure i read in the past that some languages have had issues with numbers in var names, perhaps more so where a var's data is a number. i think to be extra safe a lot of folk got into a habit of avoiding using numbers in vars name full stop.

so i don't think people are just being fussy with this i1/i2 stuff, use iA, iB if doing such makes it easier for you to read.. not everyone uses i, j because j is just an i with a tail. i've seen a lot of folk over the years skip j and use i, k much like the army skip five during countdowns.
My coding is so bad I often do use numbers.. to be honest, I didn't really know it was bad. I just understood it more with numbers than letters... e.g. a1 and a2 would mean more to me than foo and bar...
 
Back
Top Bottom