i have this function to get the index key of an element in $clientsObjects array.
each element in the array keeps an object of the Client class which have a getSocket() method which returns a socket resource.
i’m 100% sure the the $socket function parameter is equal to one of the Client->getSocket() which are in the array.
from some reason the code never enters the if statement…
any suggestions ?
function getClientObjectKey($socket)
{
global $clientsObjects;
while ($sock = current($clientsObjects))
{
if ($sock->getSocket() == $socket)
return key($clientsObjects);
$sock = next($clientsObjects);
}
}
you can do the same using
foreachwich would give you direct access to the key and do the iteration for you, sop you don’t have to mess around withcurrent,nextandkey:anyway, using
key()shouldn’t be a problem in your case, so i assume there’s a difference between the objects you try to compare.