herghost Posted January 15, 2012 Share Posted January 15, 2012 Hi all What I am trying to achieve is a for each loop for the following output Array ( [result] => success [source] => getDirectory [success] => Array ( [0] => /root/mc/world/data/ [1] => /root/mc/world/level.dat [2] => /root/mc/world/level.dat_old [3] => /root/mc/world/players/ [4] => /root/mc/world/players/herghost.dat [5] => /root/mc/world/region/ [6] => /root/mc/world/region/r.-1.0.mcr [7] => /root/mc/world/region/r.0.0.mcr [8] => /root/mc/world/session.lock [9] => /root/mc/world/uid.dat ) ) How would I go about saving each path from the [success] output? Basically I wish to loop through the array and delete the files. Many Thanks Link to comment https://forums.phpfreaks.com/topic/255076-help-with-counting-array-output/ Share on other sites More sharing options...
AyKay47 Posted January 15, 2012 Share Posted January 15, 2012 $arr = your array; Foreach($arr['success'] as $key=>$val){ // execute code for $arr['success'] } Link to comment https://forums.phpfreaks.com/topic/255076-help-with-counting-array-output/#findComment-1307910 Share on other sites More sharing options...
herghost Posted January 15, 2012 Author Share Posted January 15, 2012 Thats exactly where I got to before I hit the problem Say I am just trying to echo each one with a line break? I cant work out what to call as it is numeric? Cheers Dave Link to comment https://forums.phpfreaks.com/topic/255076-help-with-counting-array-output/#findComment-1307915 Share on other sites More sharing options...
AyKay47 Posted January 15, 2012 Share Posted January 15, 2012 Thats exactly where I got to before I hit the problem Say I am just trying to echo each one with a line break? I cant work out what to call as it is numeric? Cheers Dave If you are trying to output each value on a new line, echo them with a line break. Foreach($arr['success'] as $value){ echo $value . "<br />"; } Or you can store the values in an array for later use. Link to comment https://forums.phpfreaks.com/topic/255076-help-with-counting-array-output/#findComment-1307920 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.