rhyspaterson Posted May 28, 2007 Share Posted May 28, 2007 Hey guys, Searching through an array to find a specific string, which is fine and working. The code i am using is //$userToEdit is the user i want to edit //$userToEditLength is the string length of the name of the user i want to edit (i have also added '3' to the length to compensate for the <n>) foreach ($arrayText as $t) { if (substr($t, 0, $userToEditLength) == "<n>$userToEdit") { echo "String Matched!"; } } This all works fine. However, i would also like to output (now that i have found found the string exists) what array value the string resides in. I.e, does the $userToEdit string exist in $arrayText[2], or $arrayText[5] or $arrayText[4123]. Is there any way to do this in my substr if statement? Cheers lads. Link to comment https://forums.phpfreaks.com/topic/53250-solved-returing-the-arrayx-value/ Share on other sites More sharing options...
rhyspaterson Posted May 28, 2007 Author Share Posted May 28, 2007 Ok, figured it out. Just needed a variable below my foreach Code looks like this now: $lineNumber = 0; foreach ($arrayText as $t) { $lineNumber = $lineNumber + 1; if (substr($t, 0, $userToEditLength) == "<n>$userToEdit") { echo "<br />String Matched!"; echo $lineNumber; // the username is therefore the next string argument } } exit(); Link to comment https://forums.phpfreaks.com/topic/53250-solved-returing-the-arrayx-value/#findComment-263135 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.