I'm currently trying to get my php ldap backend to parse the ldap array into a normal array with the following layout (this is to pass back to an ajax call to then output into a table underneath a live directory search):
--NA
--(dynamic row entry)
--name
--office address
--telephone number
--mail
I manage to get my code :
//NEW ARRAY FOR COLUMN AND ROW
$na = array( array( ));
//MAKES IT EASIER TO RUN THROUGH ARRAY
$barray = array( cn , physicaldeliveryofficename , telephonenumber , mail );
//GOES THROUGH EACH ENTRY OUTPUTTING THAT ROW
for ($row=0; $row<$entries['count']; $row++) {
echo '<br />';
$na[] = $row;
//ADD EACH COL TO ARRAY AND DATA INTO COL
for ($col=0; $col<5; $col++) {
$na[$row][] = $col;
$na[$row][$col] = $entries[$row][$barray[$col]][0];
echo $na[$row][$col] . ' ';
}
}
Working to get the first row of names to output, then the for loop continues and outputs the correct amount of rows (for the parameter I tested with anyway, checked with a series of echo statements).
Can anyone give me tips as to why my code isn't working, and how to improve the code. Lastly any more efficient pointers would help as I'm more used to java than PHP. (summer job want it doing in PHP though)
Thanks in advance, Joe
EDIT - VAR_DUMP
array(18) { [0]=> array(5) { [0]=> string(14) "Steven Johnson" [1]=> string(7) "Heywood" [2]=> string(11) "01706694297" [3]=> string(29) "[email protected]" [4]=> NULL } [1]=> int(0) [2]=> int(1) [3]=> int(2) [4]=> int(3) [5]=> int(4) [6]=> int(5) [7]=> int(6) [8]=> int(7) [9]=> int(8) [10]=> int(9) [11]=> int(10) [12]=> int(11) [13]=> int(12) [14]=> int(13) [15]=> int(14) [16]=> int(15) [17]=> int(16) }
**EDIT 2 - SOLUTION:
After Barbara's comment I output the var_dump above, this lead me to see that the problem at hand was that the array was being declared in numerous different instances which was affecting the end array. Since I was instantiating the first row as a single array, then instantiating it as a multidimensional array then finally adding the data into the array.
To solve the problem I simply removed the $na[] = $row and $na[$row][] = $col parts to correctly make the array. **