I have a multi-dimensional array, that I'm reading in from a file. here is the array:
<? $userArray = array (
"onejdc" => array (
$idcs => "no",
$pwd => "peterp",
$pcs => "yes",
$pwr => "admin",
$fsn => "John",
$lsn => "Collins",
$eml => "onejdc@yahoo.com",
),
"testing" => array (
$idcs => "no",
$pwd => "testing",
$pcs => "no",
$pwr => "poster",
$fsn => "",
$lsn => "",
$eml => "",
),
"jkd" => array (
$idcs => "no",
$pwd => "jkdpw",
$pcs => "no",
$pwr => "admin",
$fsn => "Jason",
$lsn => "Davis",
$eml => "blah.com",
),
"admin" => array (
$idcs => "no",
$pwd => "adminpw",
$pcs => "no",
$pwr => "admin",
$fsn => "Administrator",
$lsn => "Bob",
$eml => "bobDole",
));?>
I'd like to be able to go through the file, and find a match. for example, locate user 'admin' by comparing that with a variable I have elsewhere.
My current code replaces fine....but when I try and edit it a second time, it screws up by adding pieces of the array in places it shouldn't.
Here's the code that I have that partially works:
for ($x = 1; $x< sizeof($buser); $x++) {
$idlen = strlen($userID);
$idlen = $idlen + 2;
if (substr($buser[$x],0,$idlen) == "\"$userID\"") {
$buser[($x+1)] = "\$idcs => \"yes\",\r\n";
$buser[($x+2)] = "\$pwd => \"$newPass\",\r\n";
$buser[($x+3)] = "\$pcs => \"$pwcs\",\r";
$buser[($x+5)] = "\$fsn => \"$firstName\",\r\n";
$buser[($x+6)] = "\$lsn => \"$lastName\",\r\n";
$buser[($x+7)] = "\$eml => \"$newEmail\",\r\n";
}
} for ($x = 0; $x <= sizeof($buser); $x++) {
$toPrint = $buser[($x)];
fputs($config, "$toPrint");
}
if anyone can help me, I'd be greatly appreciative!!! (note that I must be able to write back to the file (the file contains the array only, all flushed w/no whitespace)