Jump to content

finding key position of specified value in multi-dimensional array


meltingpoint

Recommended Posts

$openedfile = fopen($tfc_file4, "r");
$rc = 1;
while(!feof($openedfile))
{
$rc++;
$hold[$rc] = explode("|" , trim(fgets($openedfile)));
}
fclose($openedfile);

 

How can I loop through each $hold[$rc] and check if there is an $x_value in that particular array?  Also- if there is an $x_value then need to know the what array in $hold has it?

 

So the loop through would tell me that $x_value is located in $hold[2]  - for example.  While it's exact position may be in $hold[2][4] - I do not need to know that. 

 

Any help would be appreciated.

Melting..............

 

Link to comment
Share on other sites

$count =1;
while($count <= $x)
{
if(in_array($last_name, $hold[$count]))
{
echo $count;
exit;
}
$count++;
}
//
echo "if the code got this far- there was no match";

 

Ok- this works and will echo the correct # for the array.  However- if I try to make $count

equal to a $line and then use $line outside the loop- it does not work.  It echo $count out as an integer of the itteration of the loop- but I cannot seem to assign it an integer value outside the loop.

 

Any thoughts.................this is driving me crazy.

 

 

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.