I got confused when trying to access an element of an array directly with its index. I think I could better explain this in encoding: -
I have an object of the Employee class, and I TypeCast its array and tried to display it as follows:
$arrOfObj = (array) $objEmployee; $arrKeys = array_keys( $arrOfObj ); display( $arrOfObj );
this gives me the following result: -
Array ( [*m_UserId] => 1155 [*m_EmailPassword] => [*m_IsAssignedToManagementCompany] => [*m_ManagementCompanyId] => [*m_DepartmentId] => 3 [*m_DesignationId] => 4 [*m_EmployeeCompletedMonth] => [*m_EmployeeCompletedDay] => [*m_EmailAddress] => showket.mca@gmail.com ------ ------ )
Now I do not understand this Star (*). when my member variables are simple, like m_UserId, m_EmialPassword, etc., where does this Star get from it. and when I try to display the same with the following two statements, I got an error: -
display( $arrOfObj['*m_EmailAddress'] );
or
display( $arrOfObj['m_EmailAddress'] );
Both give an undefined index error message : m_EmailAddress
And when I try to do it this way, it works fine: -
display( $arrOfObj[$arrKeys[8]] );
The latter works just fine, can anyone explain the problem to me.
display( $arrOfObj[$arrKeys[11]] ); display( $arrOfObj['m_strEmailAddress'] );
Scorpion
source share