Hi
Imagine we have an array like the following,
The values, 10, 20 are the userids. I want to send text messages to my users. What is the best way to iterate through this array to get the following:
userid
phone type (work_phone, home_phone)
mobile number
$data = array(
'10' => array(
'work_phone' => array(
'9988776655', '7788665544'
),
'home_phone' => array(
'94455667733', '6655447733'
)
),
'20' => array(
'home_phone' => array(
'3333333333', '4444444444', '5555555555'
)
),
);
I am doing it in the following way, is this the best approach?
foreach ($data as $userID => $val) {
foreach ($val as $type => $key) {
foreach ($key as $number) {
echo 'User ID is: ' . $userID, "\n";
echo "Mobile Type is: " . $type, "\n";
echo "Mobile number is: " . $number, "\n\n\n";
}
}
}