Pyr3x Posted October 23, 2011 Share Posted October 23, 2011 I have an array here that looks like this: Array ( [server_info] => Array ( [up] => 1 [up_since] => Sun, 23 Oct 2011 04:04:01 -0600 [up_for] => 2588 [version] => Beta 1.9 Prerelease 4 ) [players] => Array ( [0] => Pyr3x ) [server_settings] => Array ( [map] => Underworld [pvp] => 1 [pve] => 1 [max] => 50 ) [admins] => [ops] => Array ( ) ) How would I for example print the contents of the players array without having to be specific on which object within it that I wish to print, it's dynamic so it's always going to change. Example of the output I'd like is: Players: Pyr3x, SomeGuy, AnotherGuy Thank you for any help you may be able to provide. -Pyr3x Quote Link to comment https://forums.phpfreaks.com/topic/249629-array-assistance/ Share on other sites More sharing options...
awjudd Posted October 23, 2011 Share Posted October 23, 2011 // Assuming $arr is your array name (the one you are print_r'ing). echo 'Players: ', implode(',', $arr['players']); This will emit all of the players in a CSV. ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/249629-array-assistance/#findComment-1281539 Share on other sites More sharing options...
Pyr3x Posted October 23, 2011 Author Share Posted October 23, 2011 That is awesome! Thank you sir! One last question if that is OK. How would I grab clean data from the field: Array ( [server_info] => Array ( [up] => 1 [up_since] => Sun, 23 Oct 2011 04:04:01 -0600 [up_for] => 2588 [version] => Beta 1.9 Prerelease 4 ) } Example: [up_for] Also how do I convert that value to hours:min:seconds Quote Link to comment https://forums.phpfreaks.com/topic/249629-array-assistance/#findComment-1281654 Share on other sites More sharing options...
awjudd Posted October 24, 2011 Share Posted October 24, 2011 Echo the up_for value: echo $arr [ 'server_info' ] [ 'up_for' ]; You would use one of the string functions (i.e. http://php.net/manual/en/function.date.php) to convert the time to a readable time. ~juddster Quote Link to comment https://forums.phpfreaks.com/topic/249629-array-assistance/#findComment-1281665 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.