Merhaba,
Okuduğum dizilerde (multidimensional veya onedimensional) olarak bazı parametreleri fonksiyon içerisinde silip veya seçip MD5 kodu çıkarmak istiyorum. Bu işlemi yazan bir fonksiyon yaptım. Ama class içerisinde kullandığım dizideki elemanlar da siliniyor. Sadece fonksiyon içerisindeki kullanımda bu değerleri seçmek veya silmek isityorum.
Örnek kullanım:
for ($i = 0; $i < $product_count; $i++) {
$integrationOperations = new IntegrationOperations();
$info_MD5_Code = $integrationOperations->GetMD5($product_list[$i], [
"ItemDescription",
"ItemTaxGrCode",
"ProductAtt01Desc",
"ProductAtt02Desc",
"ProductAtt03Desc",
"ProductAtt04Desc",
"ProductAtt05Desc",
"ProductAtt06Desc",
"ProductAtt07Desc",
"ProductAtt08Desc"],1); }
function GetMD5($product, $optionList = [], $optionType = 0)
{
foreach ($product as $key => $product_item) {
if (is_object(json_decode(json_encode($product_item), true))) {
unset($product->{$key});
}
if (!empty($optionList)) {
if ($optionType == 1) {
if(is_numeric($key))
{
foreach ($product_item as $key2 => $product_item_2) {
$key_status = false;
foreach ($optionList as $optionName) {
if ($optionName == $key2) {
$key_status = true;
}
}
if ($key_status == false) {
unset($product_item->{$key2});
}
}
}
else
{
$key_status = false;
foreach ($optionList as $optionName) {
if ($optionName == $key) {
$key_status = true;
}
}
if ($key_status == false) {
unset($product->{$key});
}
}
}
else
{
if(is_numeric($key))
{
foreach ($product_item as $key2 => $product_item_2) {
foreach ($optionList as $optionName) {
if ($optionName == $key2) {
unset($product_item->{$key2});
}
}
}
}
else
{
foreach ($optionList as $optionName) {
if ($optionName == $key) {
unset($product->{$key});
}
}
}
}
}
}
return md5(serialize($product));
}
is_number kontrolünü multidimensional array gelirse diye yaptım. Şu anki kullanım sadece object array tipinde gelen değerler için geçerli. Bunun sadece array tipinde olanlarını da yapacağım.
Unsetin sadece GetMD5 fonskiyonunun içerisinde geçerli olmasını istiyorum.