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..............

 

$count =1;

while($count < sizeof($hold))
{
if(in_array($hold[$count], $last_name))
   {
   $p = array_search($last_name, $hold[$count])
   }
}

echo $p;

 

Would this work or should I create a function to do it.  - Not at home to test this.

 

Meltingpoint

$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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.