Created
October 7, 2016 12:48
-
-
Save Balamir/a86d7cc3fe30806c38635331f59fbcb7 to your computer and use it in GitHub Desktop.
PHP: strpos_array is strpos that can take an array as needle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Dizi verisinin icinde, dizi olarak verilen elemanlari arar. | |
| * | |
| * strpos fonksiyonun array surumudur. Veriler array ya da string olabilir. | |
| * Deger bulunamazsa false, aksi taktirde bulundugu pozisyon doner. | |
| * | |
| * @param array|string $haystack Icinde arama yapilacak array ya da string | |
| * @param array|string $needles Aranacak array ya da string | |
| * @param integer $offset | |
| * @return bool|int $haystack icinde $needles elemanlari bulunamazsa false, bulunursa pozisyon | |
| */ | |
| function strpos_array($haystack, $needles, $offset = 0) { | |
| if (is_array($needles)) { | |
| foreach ($needles as $needle) { | |
| if ( is_array( $haystack ) ) { | |
| foreach ($haystack as $stack) { | |
| $pos = strpos_array( $stack, $needle ); | |
| if ($pos !== false) { | |
| return $pos; | |
| } | |
| } | |
| } else { | |
| $pos = strpos_array($haystack, $needle); | |
| if ($pos !== false) { | |
| return $pos; | |
| } | |
| } | |
| } | |
| return false; | |
| } else { | |
| return strpos($haystack, $needles, $offset); | |
| } | |
| } | |
| $needles = array( 'FI1_ARA_23434', 'FI1_FIN_23434', 'FI1_PAKET_23434'); | |
| $haystack = array('PAKET'); | |
| print_r(strpos_array($haystack, $needles)); // will return 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment