I am generating a dictionary in PHP where key and values are added to the dictionary.
But I am not able to fetch the values back. I am using following code:
//some code here
while (($line = fgets($fileServices)) !== false) {
//echo $line.'....................';
if (strpos($line,'header') == false){
$serviceName=explode(",", $line)[0];
$RestartData=explode(",", $line)[1];
$StatusData=explode(",", $line)[2];
$serviceRestartMappingdict[$totalServices]= $serviceName.':'.$RestartData;
$serviceStatusMappingdict[$totalServices]= $serviceName.'_'.$StatusData;
$totalServices = $totalServices+1;
}
}
$counter=0;
//echo $serviceStatusMappingdict[0];
fclose($fileServices);
$counter=0;
for ($i = 0; $i < count($serviceStatusMappingdict); ++$i){
echo '<<<<<<<<<<<<<<<<<<<<<<<'.$serviceStatusMappingdict[$i].'>>>>>>>>>>>>>>>>>>>>>>>>>>>';
}
If I do an echo like echo $serviceStatusMappingdict[0];, I get the value but when I use a loop to access the data I do not get any value.
echo $serviceStatusMappingdict[1];?print_r ($serviceStatusMappingdict);so we can help youprint 'Type: ' . gettype($serviceStatusMappingdict) . "\n" ; print 'Count: ' . count($serviceStatusMappingdict) . "\n\n"; foreach ($serviceStatusMappingdict as $key => $value) { echo gettype ($key) . "\n"; echo $value . "\n"; echo $serviceStatusMappingdict[$key] . "\n\n"; }