zander1983 Posted October 27, 2011 Share Posted October 27, 2011 Hi I have an array which looks like this when i do a print_r(): Array ( [0] => Array ( [path] => 1 [order] => 2 ) [1] => Array ( [path] => 2 [order] => 1 ) [2] => Array ( [path] => 3 [order] => 2 ) ) In this instance, I want to change the values of the order key. So I do something like this so that the last array has a path of 3 and an order of 1, and the others have orders of 2 foreach ($old_images as $old_image){ if($old_image['path']==3){ $old_image['order']="1"; } else{ $old_image['order']="2"; } } When i step through, i see that the order is changed, but when i do a print_r(), i get the same result. So even though im resetting the order value of the inside arrays, the multidimensional array does not change.... any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/249902-changing-values-of-a-multidimensional-array/ Share on other sites More sharing options...
PFMaBiSmAd Posted October 27, 2011 Share Posted October 27, 2011 You are changing values in $old_image. $old_image is not the original array. It is a copy of each element of the original array that the foreach() statement sets. You would need to set the values in the $old_images array. Quote Link to comment https://forums.phpfreaks.com/topic/249902-changing-values-of-a-multidimensional-array/#findComment-1282651 Share on other sites More sharing options...
zander1983 Posted October 27, 2011 Author Share Posted October 27, 2011 ok thanks, thats fixed it Quote Link to comment https://forums.phpfreaks.com/topic/249902-changing-values-of-a-multidimensional-array/#findComment-1282657 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.