Skip to content

Instantly share code, notes, and snippets.

@ademalp
Created March 27, 2013 09:15
Show Gist options
  • Save ademalp/5252900 to your computer and use it in GitHub Desktop.
Save ademalp/5252900 to your computer and use it in GitHub Desktop.
POST ya da herhangi bir dizinin keylerini verilen patterne göre filtreler.
<?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"));
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