-
Notifications
You must be signed in to change notification settings - Fork 168
/
PHP_Custom_Array_Value_Duplication_Replace_with_String_Replace_Function.php
104 lines (97 loc) · 3.62 KB
/
PHP_Custom_Array_Value_Duplication_Replace_with_String_Replace_Function.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
function custom_replace($find,$replace,$string){
$replaced = "";
for ($i=0; $i < strlen($string); $i++) {
if (strlen($find)>1) {
if ($string[$i] == $find[0]) {
$temp = "";
for ($j=0; $j < strlen($find); $j++) {
if (isset($string[$i+$j])) {
$temp.=$string[$i+$j];
}
}
if ($temp == $find) {
$replaced.=$replace;
$i=$i+strlen($find)-1;
}else{
$replaced .=$string[$i];
}
}else{
$replaced .=$string[$i];
}
}else{
if ($string[$i] == $find) {
$replaced .=$replace;
}else{
$replaced .=$string[$i];
}
}
}
return $replaced;
}
$EmployeesNames =array(
array('Classname'=>"Masroor Sommro Haider Solangi",'TwoClassname'=>array('Classname'=>"Kazim Ali Haider Solangi","childrens"=>array(
array('Classname'=>"Kazim Ali Haider Solangi",),
array('Classname'=>"Kiran Khan Haider Solangi"),
array('Classname'=>"Sanam Ali Haider Solangi",)
)),'Deptname'=>"Masroor Sommro Haider Solangi","childrens"=>array(
array('Classname'=>"Kazim Ali Haider Solangi","childrens"=>array(
array('Classname'=>"Kazim Ali Haider Solangi",),
array('Classname'=>"Kiran Khan Haider Solangi"),
array('Classname'=>"Sanam Ali Haider Solangi",)
)),
array('Classname'=>"Kiran Khan Haider Solangi"),
array('Classname'=>"Sanam Ali Haider Solangi")
)),
array('Classname'=>"Ali Khan Haider Solangi",'Deptname'=>"Masroor Sommro Haider Solangi","childrens"=>array(
array('Classname'=>"Kazim Ali Haider Solangi",'Deptname'=>"Masroor Sommro Haider Solangi"),
array('Classname'=>"Kiran Khan Haider Solangi"),
array('Classname'=>"Sanam Ali Haider Solangi")
)),
array('Classname'=>"Kamran Mughsi Haider Solangi","childrens"=>array(
array('Classname'=>"Kazim Ali Haider Solangi"),
array('Classname'=>"Kiran Khan Haider Solangi"),
array('Classname'=>"Sanam Ali Haider Solangi")
)),
array('Classname'=>"Zubair Ahmed Jatoi Haider Solangi"),
array('Classname'=>"Masroor Sommro Haider Solangi","childrens"=>array(
array('Classname'=>"Kazim Ali Haider Solangi"),
array('Classname'=>"Kiran Khan Haider Solangi"),
array('Classname'=>"Sanam Ali Haider Solangi")
)),
array('Classname'=>"Muhammad Ali Haider Solangi", "childrens"=>array(
array('Classname'=>"Kazim Ali Haider Solangi","childrens"=>array(
array('Classname'=>"Kazim Ali Haider Solangi"),
array('Classname'=>"Kiran Khan Haider Solangi"),
array('Classname'=>"Sanam Ali Haider Solangi")
)),
array('Classname'=>"Kiran Khan Haider Solangi"),
array('Classname'=>"Sanam Ali Haider Solangi")
)),
);
$new_array = array();
echo "<pre>";
echo "Old Array : zzzz";
echo "<br/>";
print_r($EmployeesNames);
echo "<br/>";
function replace_name_array($array)
{
foreach ($array as $key => $value) {
if (is_array($value)) {
$new["$key"] = replace_name_array($value);
}else{
$value = custom_replace("Haider Solangi", "" , $value);
$new["$key"] = $value;
}
}
return $new;
}
$new_array = replace_name_array($EmployeesNames);
echo "<pre>";
echo "New Array : zzzz";
echo "<br/>";
print_r($new_array);
echo "<br/>";
die;
?>