Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- array(
- 0=>"1-2",
- 1=>"2-3"
- 2=>"3-4"
- 3=>"4-3"
- )
- $input = array(
- 0 => "1-2",
- 1 => "2-3",
- 2 => "3-4",
- 3 => "4-3",
- );
- $search = '2-';
- $index = -1;
- foreach ($input as $key => $value) {
- if (strpos($value, $search) === 0) {
- $index = $key;
- break;
- }
- }
- <?php
- $find = '2-';
- $array = array(0=>"1-2", 1=>"2-3", 2=>"3-4", 3=>"4-3");
- $position = NULL;
- foreach($array as $key=>$val){
- if( substr($val,0,strlen($find)) == $find ){
- $position = $key;
- break;
- }
- }
- echo $position;
- $needle = '2-';
- $result = array_filter(
- $myArray,
- function($value) use ($needle) {
- return fnmatch($needle.'*', $value);
- }
- );
- var_dump($result);
- $input = array('1-2', '2-3', '3-4', '4-3');
- $search = '2-';
- var_dump(preg_grep("/^{$search}/", $input));
- $input = array('1-2', '2-3', '3-4', '4-3');
- $search = '2-';
- $results = array_filter(
- $input,
- function ($item) use ($search) {
- return strpos($item, $search) === 0;
- }
- );
- // $results will contain an array of all strings that match.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement