Boxerman Posted May 16, 2015 Share Posted May 16, 2015 Hey guys, I've trying to explode and array but having no luck: The array is grabbed via: $result = $adldap->group()->all($includeDescription = false, $search = "*", $sorted = false); and the output looks a little like: array(1500) { [0]=> string(16) "Exchange Servers" [1]=> string(36) "Exchange Organization Administrators" [2]=> string(33) "Exchange Recipient Administrators" [3]=> string(33) "Exchange View-Only Administrators" [4]=> string(37) "Exchange Public Folder Administrators" [5]=> string(21) "ExchangeLegacyInterop" [6]=> The command i have so far is: foreach ($result as $group) { $items = explode('[', $group); foreach($items as $element) { list($key, $value) = explode('"', $element); if ($key==']') { echo "$value</a>"; } } } I honestly don't know what to use for the explode as i wanted to try starting with ) and ending with " but i can't get my head around the idea.. Any help would be high fived. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/296355-exploding-array/ Share on other sites More sharing options...
fastsol Posted May 17, 2015 Share Posted May 17, 2015 There isn't a [ in any of the array values, so that isn't going to work. The only common thing between all the array items is the word Exchange. Not much else you could consistently explode by in that array. The [ and ] symbols are the array keys, not the array items. Quote Link to comment https://forums.phpfreaks.com/topic/296355-exploding-array/#findComment-1512053 Share on other sites More sharing options...
Solution Ch0cu3r Posted May 17, 2015 Solution Share Posted May 17, 2015 (edited) The output you see is what you get by passing $result to var_dump(), this will print the structure of the array and show the data types of the values stored in the array. You do not need to use explode to get the value from the array. You loop over the values in the the array using foreach and echo the value of the current item $result = $adldap->group()->all($includeDescription = false, $search = "*", $sorted = false); // this returns an array of results var_dump($result); // this will print the structure of the array // this loops over the items in the array and prints each value foreach ($result as $value) { echo $value . '<br />'; } Explode is used for splitting a string into an array. Edited May 17, 2015 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/296355-exploding-array/#findComment-1512061 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.