Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. array(4) {
  2. [0]=>
  3. array(2) {
  4. ["id"]=>
  5. string(4) "id-1"
  6. ["articles"]=>
  7. array(2) {
  8. [0]=>
  9. array(1) {
  10. ["data"]=>
  11. array(6) {
  12. ["art"]=>
  13. string(6) "108108"
  14. ["type"]=>
  15. string(0) ""
  16. ["pos"]=>
  17. string(3) "125"
  18. ["kleur"]=>
  19. string(4) "3750"
  20. ["height"]=>
  21. string(3) "179"
  22. ["foto"]=>
  23. string(2) "01"
  24. }
  25. }
  26. [1]=>
  27. array(1) {
  28. ["data"]=>
  29. array(6) {
  30. ["art"]=>
  31. string(0) ""
  32. ["type"]=>
  33. string(0) ""
  34. ["pos"]=>
  35. string(3) "163"
  36. ["kleur"]=>
  37. string(0) ""
  38. ["height"]=>
  39. string(0) ""
  40. ["foto"]=>
  41. string(0) ""
  42. }
  43. }
  44. }
  45. }
  46. [2]=>
  47. array(2) {
  48. ["id"]=>
  49. string(7) "ui-id-2"
  50. ["articles"]=>
  51. array(2) {
  52. [0]=>
  53. array(1) {
  54. ["data"]=>
  55. array(6) {
  56. ["art"]=>
  57. string(0) ""
  58. ["type"]=>
  59. string(0) ""
  60. ["pos"]=>
  61. string(3) "944"
  62. ["kleur"]=>
  63. string(0) ""
  64. ["height"]=>
  65. string(0) ""
  66. ["foto"]=>
  67. string(0) ""
  68. }
  69. }
  70. [1]=>
  71. array(1) {
  72. ["data"]=>
  73. array(6) {
  74. ["art"]=>
  75. string(0) ""
  76. ["type"]=>
  77. string(0) ""
  78. ["pos"]=>
  79. string(3) "586"
  80. ["kleur"]=>
  81. string(0) ""
  82. ["height"]=>
  83. string(0) ""
  84. ["foto"]=>
  85. string(0) ""
  86. }
  87. }
  88. }
  89. }
  90. }
  91.  
  92. foreach($data as $key => $value) {
  93. if($value['id'] === "id-1") {
  94. foreach($value as $tweek => $tweev) {
  95. foreach($tweev as $driek => $driev) {
  96. foreach($driev as $vierk => $vierv) {
  97. if($vierv['pos'] === "163") {
  98. // This is the right article! I think...
  99. echo $vierv['pos'] . "<br />"; // shows 163!
  100. foreach($vierv as $vijfk => $vijfv) {
  101. // What to do?!?!
  102. }
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109.  
  110. <?php
  111. $a1=array("a"=>"red","pos"=>"364");
  112. $a2=array($a1,"1"=>"blue","2"=>"yellow");//one array inside another to simulate your multi depth array
  113.  
  114. array_walk_recursive($a2,"myfunction");//use array_recursive
  115.  
  116.  
  117. function myfunction($value,$key)
  118. {
  119. if ($key == 'pos' && $value == '364') { //set your condition here
  120. echo "change your key or value here";
  121. }
  122. }
  123. ?>
  124.  
  125. arr = array(
  126. 0=>array(
  127. 'id'=>"id-1",
  128. 'articles'=> array(
  129. 0=>array(
  130. 'data'=> array(
  131. 'art'=> "108108"
  132. 'type'=> ""
  133. 'pos'=> "125"
  134. 'kleur'=> "3750"
  135. 'height'=> "179"
  136. 'foto'=> "01"
  137. ),
  138. ),
  139.  
  140.  
  141. 1=> array(
  142. 'data'=> array(
  143. 'art'=> ""
  144. 'type'=> ""
  145. 'pos'=> "163"
  146. 'kleur'=> ""
  147. 'height'=> ""
  148. 'foto'=> ""
  149. ),
  150. ),
  151. ),
  152. ),
  153. 2=> array(
  154. 'id'=>"ui-id-2"
  155. 'articles'=> array(
  156. 0=> array(
  157. 'data'=> array(
  158. 'art'=> ""
  159. 'type'=> ""
  160. 'pos'=> "944"
  161. 'kleur'=> ""
  162. 'height'=> ""
  163. 'foto'=> ""
  164. ),
  165. ),
  166. 1=> array(
  167. 'data'=> array(
  168. 'art'=> ""
  169. 'type'=> ""
  170. 'pos'=> "586"
  171. 'kleur'=> ""
  172. 'height'=> ""
  173. 'foto'=> ""
  174. ),
  175. ),
  176. ),
  177. ),
  178. );
  179.  
  180. foreach ($arr as $key=>value)
  181. if ($value['id'] == 'id-1')
  182. foreach($value as $key2=>$value2)
  183. if ($value2['pos'] == 163)
  184. $value2['art'] = $newArtValue;
  185.  
  186. $arr = array(
  187. 'id-1'=>array(
  188. 'articles'=> array(
  189. 125=>array(
  190. 'art'=> "108108"
  191. 'type'=> ""
  192. 'kleur'=> "3750"
  193. 'height'=> "179"
  194. 'foto'=> "01"
  195. ),
  196. 163=> array(
  197. 'art'=> ""
  198. 'type'=> ""
  199. 'kleur'=> ""
  200. 'height'=> ""
  201. 'foto'=> ""
  202. ),
  203. ),
  204. ),
  205. 'ui-id-2'=> array(
  206. 'articles'=> array(
  207. 944=> array(
  208. 'art'=> ""
  209. 'type'=> ""
  210. 'kleur'=> ""
  211. 'height'=> ""
  212. 'foto'=> ""
  213. ),
  214. 586=> array(
  215. 'art'=> ""
  216. 'type'=> ""
  217. 'kleur'=> ""
  218. 'height'=> ""
  219. 'foto'=> ""
  220. ),
  221. ),
  222. ),
  223. );
  224.  
  225. $arr['id-1'][163]['art'] = $newArtValue;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement