Jump to content

Need help formatting a multi-dimensional array result


Recommended Posts

Hey everyone, I have an array result that I am having a difficult time formatting to a more human-readable format.Here is the an example, it came from an LDAP query:

array(2) {  ["uid=tthompson,ou=People,dc=abc,dc=com"]=>  array(7) {	["logintimeremaining"]=>	string(1) "2"	["account"]=>	string(15) "left/2008-05-10"	["department"]=>	string(22) "Specialty Pool"	["affiliation"]=>	string(15) "former-it"	["displayname"]=>	string(13) "Tom Thompson"	["mail"]=>	string(16) "tthompson@abc.com"	["uid"]=>	string(8) "tthompson"  } ["uid=ttomlin,ou=People,dc=abc,dc=com"]=>  array(9) {	["pwdchanged"]=>	string(15) "20101015153716Z"	["logintimeremaining"]=>	string(1) "2"	["passwordexpiration"]=>	string(15) "20111015153716Z"	["locked"]=>	string(5) "FALSE"	["department"]=>	string(7) "Requisitions"	["affiliation"]=>	string(7) "faculty"	["displayname"]=>	string(20) "Mr. Tom Tomlin"	["mail"]=>	string(15) "ttomlin@abc.com"	["uid"]=>	string(7) "ttomlin"  }}

The end user won't care for the length of the strings, or the top level key/values. Can any array wizards give this a look? Thanks.

Edited by jwburnside
Link to post
Share on other sites

How do you want it present it to them? As an array, or are you trying to present it them on a webpage? Which part are you interested in? Using a foreach loop should give you access to any key or value you need. From there you can do whatever you want.

Link to post
Share on other sites

Thanks for the reply. I'm not really worried about any HTML formatting besides line breaks. It can be very rudimentary, for instance this would certainly suffice:

["logintimeremaining"]=> "2"["account"]=> "left/2008-05-10"["department"]=> "Specialty Pool"

etc.I just can't seem to figure out how to arrange my loop to only print out the relevant key/value pairs. Also, I didn't mentioned before but the previous example was formatted with <pre> tags; otherwise it just outputs as a normal array dump style.

Link to post
Share on other sites

Use print_r instead of var_dump.echo "<pre>".print_r($tmpArray, true)."</pre>";EDIT:Or if you don't want the top level arrays you could do a nested foreach loop. Something like:

foreach($tmpArray as $subArray) {   foreach($subArray as $Key => $Value) {	  echo $Key." => ".$Value."<br />";   }   echo "<br />";}

Edited by ShadowMage
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...