Jump to content

ubunken

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

ubunken's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. realised it should have been "stripos". Thanks
  2. Hi guys i was wondering if there was a way for me to have a case insensitive search for foreach(). For example <?php $clamarr = array( 'i am high', 'i am low', 'i am Found' ); function checkArray($arr, $search) { for each($arr as $key => $value) { $find = strpos($value, $search); if ($find !== false) { return $key; } } return FALSE; } $result = checkArray($clamarr, found); if ($result !== FALSE) { echo $result; }else{ echo "not found"; } ?> The main purpose of this is that i would be using this method for several arrays and in each array the case of the word found would be different (i.e. Found, found, FOUND) so i was thinking if there was a way for me to traverse the arrays with the method instead of manually substituting the value "found" for all the different arrays.
  3. Thank you DarkWater, the method works now, however it is still unable to print out the variable. Seems like there's an error somewhere. It looks like it is not going through each element in the array
  4. Hi i tried using the way suggested however i received an error that states "Parse error: syntax error, unexpected T_STRING, expecting'("in C:\xampp\htdocs\test.php on line 14" below is my code: <?php $clamarr = array( 'i am high', 'i am low', 'i am found' ); function checkArray($arr, $search) { for each($arr as $key => $value) { $find = strpos($value, $search); if ($find !== false) { return $key; } } return FALSE; } $result = checkArray($clamarr, $found); if ($result !== FALSE) { echo $result; }else{ echo "not found"; } ?> Does anyone know what's wrong with it?
  5. Is there any way for me to just look for part of the string? And entering maybe some sort of wild card in front of the keyword?
  6. Hi guys thanks for the help. However, it seems to have a minor issue. If i change the query to for example 'mom' , the array_search seems like it can only transverse the first key. Even if i change the $query = 'mom'; the result printed out will still be 'boy'; after testing it seems like it is unable to search for the keyword 'mom' from the entire string. I tried changing the search to 'i am a mom' and it prints out perfectly, however this will not work in my actual scenario because Currently the array i have now was obtained by exploding output that was parsed into variables from command line. And in actual fact i do not have any idea what information will be displayed thus i can't explicitly state the information that i want to echo. The only thing i do know is that I need the third variable
  7. Hi all I was wondering if it is possible to extract the entire key of an array and storing it in a variable. My array contains strings: $arr[0] = I am a boy $arr[1] = I am a girl $arr[2] = I am a mom Is it possible to search through the entire array for the element by just typing in a keyword for example "boy"? my code currently goes like this: $search = array_search("boy", $arr); $who = explode(" ", $search); $captured = $who[3]; Hope you guys can help me with it because it does not work currently
×
×
  • 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.