Created
March 27, 2013 09:15
-
-
Save ademalp/5252900 to your computer and use it in GitHub Desktop.
POST ya da herhangi bir dizinin keylerini verilen patterne göre filtreler.
This file contains 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 | |
function array_pattern($array,$pattern) | |
{ | |
$return = array(); | |
foreach($array as $key => $value) | |
{ | |
$ret = sscanf($key, $pattern); | |
$pass = true; | |
foreach($ret as $val) | |
{ | |
if(is_null($val)) | |
{ | |
$pass = false; | |
break; | |
} | |
} | |
if($pass) | |
{ | |
array_push($ret,$value); | |
$return[] = $ret; | |
} | |
} | |
return $return; | |
} | |
$ar = array( | |
"resim-1-2" => "14", | |
"baska-3" => "14", | |
"resim-2" => "14", | |
"resim-14" => "14" | |
); | |
echo "resim-%d çıktısı\n\n"; | |
var_export(array_pattern($ar,"resim-%d")); | |
echo "\n\nresim-%d-%d çıktısı\n\n"; | |
var_export(array_pattern($ar,"resim-%d-%d")); |
This file contains 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
resim-%d çıktısı | |
array ( | |
0 => | |
array ( | |
0 => 1, | |
1 => '14', | |
), | |
1 => | |
array ( | |
0 => 2, | |
1 => '14', | |
), | |
2 => | |
array ( | |
0 => 14, | |
1 => '14', | |
), | |
) | |
resim-%d-%d çıktısı | |
array ( | |
0 => | |
array ( | |
0 => 1, | |
1 => 2, | |
2 => '14', | |
), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment