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. Quote 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(); Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.