J N
asked on
rearrange a multidimensional array
hi,
i have a $_POST array like so
array(6) {
["same_info"]=> string(3) "yes"
["image_name"]=> array(2) { [0]=> string(12) "gopr0012.jpg" [1]=> string(9) "photo.jpg" }
["image_location"]=> array(2) { [0]=> string(4) "calgary" [1]=> string(0) "canada" }
["image_fav"]=> array(2) { [0]=> string(2) "no" [1]=> string(0) "yes" }
["image_desc"]=> array(2) { [0]=> string(0) "description1" [1]=> string(0) "description2" }
["image_submit"]=> string(12) "Image Submit"
}
essentially this array is used to verify image data so a user can change the name of files and update some data i would like to rearrange the array so that it puts all of the relevant data is contained within one array for each file
for the array above it would like to arrange it like so
array(1) {
["same_info"]=> string(3) "yes"
}
array(4) {
["image_name"]=> string(12) "gopr0012.jpg"
["image_location"]=> string(0) "calgary"
["image_fav"]=> string(0) "no"
["image_desc"]=> string(0) "description1"
}
array(4) {
["image_name"]=> string(12) "photo.jpg"
["image_location"]=> string(0) "canada"
["image_fav"]=> string(0) "yes"
["image_desc"]=> string(0) "description2"
}
array(1){
["image_submit"]=> string(12) "Image Submit"
}
the image_submit and same_info key only need to contain one piece of data while there could be a lot of the middle arrays containing the rearranged file data
thanks a lot for your help
i have a $_POST array like so
array(6) {
["same_info"]=> string(3) "yes"
["image_name"]=> array(2) { [0]=> string(12) "gopr0012.jpg" [1]=> string(9) "photo.jpg" }
["image_location"]=> array(2) { [0]=> string(4) "calgary" [1]=> string(0) "canada" }
["image_fav"]=> array(2) { [0]=> string(2) "no" [1]=> string(0) "yes" }
["image_desc"]=> array(2) { [0]=> string(0) "description1" [1]=> string(0) "description2" }
["image_submit"]=> string(12) "Image Submit"
}
essentially this array is used to verify image data so a user can change the name of files and update some data i would like to rearrange the array so that it puts all of the relevant data is contained within one array for each file
for the array above it would like to arrange it like so
array(1) {
["same_info"]=> string(3) "yes"
}
array(4) {
["image_name"]=> string(12) "gopr0012.jpg"
["image_location"]=> string(0) "calgary"
["image_fav"]=> string(0) "no"
["image_desc"]=> string(0) "description1"
}
array(4) {
["image_name"]=> string(12) "photo.jpg"
["image_location"]=> string(0) "canada"
["image_fav"]=> string(0) "yes"
["image_desc"]=> string(0) "description2"
}
array(1){
["image_submit"]=> string(12) "Image Submit"
}
the image_submit and same_info key only need to contain one piece of data while there could be a lot of the middle arrays containing the rearranged file data
thanks a lot for your help
I started trying to copy the information in the question and reformat it for use in a test case, but it appears to be bogus. How is it that we got a var_dump() output with this?
string(4) "calgary"
Obviously, "calgary" is a 7-character string. If you can post some of the real test data, along with the expected output (the SSCCE) I'll be glad to try to help.
Best regards, ~Ray
string(4) "calgary"
Obviously, "calgary" is a 7-character string. If you can post some of the real test data, along with the expected output (the SSCCE) I'll be glad to try to help.
Best regards, ~Ray
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry about the test data i just realised that i had left it blank.
i basically just did a var_dump on the post and by mistake left some fields empty on the form so i went bank and edited it.
i dont have time to work on it right now but i will be in touch
thanks a lot!
i basically just did a var_dump on the post and by mistake left some fields empty on the form so i went bank and edited it.
i dont have time to work on it right now but i will be in touch
thanks a lot!
ASKER
THANKS RAY BIG HELP YET AGAIN!
Thanks for the points, ~Ray
http://stackoverflow.com/q