I'm trying to read a file line by line and store values to an array. and if a username already in the array occurs update existing array for the username, if not create new array.
$data[] = array('username1'=>array('failed-attempts'=>'0','ip'=>array('191.25.25.214')));
$data[] = array('username2'=>array('failed-attempts'=>'0','ip'=>array('221.25.25.214')));
I'm trying to update failed-attempts value and add a newip address to ip array if array for username exists.
I tried this
foreach($data as $d){
if (array_key_exists($username, $d)) {
//username is already in the array, update attempts and add this new IP.
}else{
$data[] = array('username3'=>array('failed-attempts'=>'0','ip'=>array('129.25.25.214'))); //username is new, so add a new array to $data[]
}
}
How do I update an existing array?