meltingpoint Posted December 13, 2009 Share Posted December 13, 2009 $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 https://forums.phpfreaks.com/topic/184992-finding-key-position-of-specified-value-in-multi-dimensional-array/ Share on other sites More sharing options...
meltingpoint Posted December 13, 2009 Author Share Posted December 13, 2009 $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 Link to comment https://forums.phpfreaks.com/topic/184992-finding-key-position-of-specified-value-in-multi-dimensional-array/#findComment-976629 Share on other sites More sharing options...
meltingpoint Posted December 14, 2009 Author Share Posted December 14, 2009 $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 https://forums.phpfreaks.com/topic/184992-finding-key-position-of-specified-value-in-multi-dimensional-array/#findComment-976814 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.