Jump to content

[SOLVED] Quickest way to tell key


thiggins09

Recommended Posts

Hi, I have an array and each key in it is labled a user's ID. I was wondering what the most efficient way to get the real place of that key would be.

 

For example:

 

$arr[342]=34;
$arr[235]=55;
$arr[164]=64;
$arr[766]=4;

 

key 342 is first in the array, 235 second an so on. So if I wanted to tell that 744 is really fourth in the array, what would be the best way?

Link to comment
Share on other sites

There isn't a specific function to find what you want, you'll have to loop through the array...

 

<?php

$arr[342]=34;
$arr[235]=55;
$arr[164]=64;
$arr[766]=4;

$key_to_find = 164;
$cnt = 1;

while ($values = each($arr)) {
if ($values['key'] == $key_to_find) {
	$place = $cnt;
	break;
}

$cnt++;
}

echo $place;

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.