ucsdmbdm
asked on
PHP two diminutional array iteration
Hi,
Whats the most efficient way of iterating through ONLY a subarray of multi-dimentional array ?
Like in the example below, how can I only iterate through the set with $topnavnames[3] without having to go through the first dimension
$bottomnavnames [$all_roles[2]][$topnavnam es[1]] = 'Timesheet';
$bottomnavtarget[$all_role s[2]][$top navnames[1 ]] = 'timesheets.php';
$bottomnavnames [$all_roles[2]][$topnavnam es[1]] = 'Expense Report';
$bottomnavtarget[$all_role s[2]][$top navnames[1 ]] = 'expenses.php';
$bottomnavnames [$all_roles[2]][$topnavnam es[1]] = 'Invoice';
$bottomnavtarget[$all_role s[2]][$top navnames[1 ]] = 'invoices.php';
$bottomnavnames [$all_roles[2]][$topnavnam es[1]] = 'Project Report';
$bottomnavtarget[$all_role s[2]][$top navnames[1 ]] = 'project_reports.php';
// I only want to iterate through this set
$bottomnavnames [$all_roles[2]][$topnavnam es[3]] = 'Application Management';
$bottomnavtarget[$all_role s[2]][$top navnames[3 ]] = 'application_management.ph p';
$bottomnavnames [$all_roles[2]][$topnavnam es[3]] = 'Job Management';
$bottomnavtarget[$all_role s[2]][$top navnames[3 ]] = 'job_manager.php';
$bottomnavnames [$all_roles[2]][$topnavnam es[3]] = 'Resource Allocation';
$bottomnavtarget[$all_role s[2]][$top navnames[3 ]] = 'resources_m.php';
$bottomnavnames [$all_roles[2]][$topnavnam es[3]] = 'Referrals';
$bottomnavtarget[$all_role s[2]][$top navnames[3 ]] = 'reference_m.php';
Thanks
Whats the most efficient way of iterating through ONLY a subarray of multi-dimentional array ?
Like in the example below, how can I only iterate through the set with $topnavnames[3] without having to go through the first dimension
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
// I only want to iterate through this set
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
Thanks
This does not look like any kind of "normal" data structure -- at least not one they teach in computer science class. You can install the code snippet and see why. It is complicated and obviously confusing, since it destroys itself (overwriting fields) as it is defined.
I'll try to show you an alternative in a separate post.
I'll try to show you an alternative in a separate post.
<?php // RAY_temp_ucs.php
error_reporting(E_ALL);
echo "<pre>" . PHP_EOL;
// MUST ASSIGN SOME VALUES TO THESE
$all_roles[2] = 'ALL_ROLES_2';
$topnavnames[1] = 'TOP_NAV_NAMES_1';
$topnavnames[3] = 'TOP_NAV_NAMES_3';
$bottomnavnames [$all_roles[2]][$topnavnames[1]] = 'Timesheet';
$bottomnavtarget[$all_roles[2]][$topnavnames[1]] = 'timesheets.php';
$bottomnavnames [$all_roles[2]][$topnavnames[1]] = 'Expense Report';
$bottomnavtarget[$all_roles[2]][$topnavnames[1]] = 'expenses.php';
$bottomnavnames [$all_roles[2]][$topnavnames[1]] = 'Invoice';
$bottomnavtarget[$all_roles[2]][$topnavnames[1]] = 'invoices.php';
$bottomnavnames [$all_roles[2]][$topnavnames[1]] = 'Project Report';
$bottomnavtarget[$all_roles[2]][$topnavnames[1]] = 'project_reports.php';
// I only want to iterate through this set
$bottomnavnames [$all_roles[2]][$topnavnames[3]] = 'Application Management';
$bottomnavtarget[$all_roles[2]][$topnavnames[3]] = 'application_management.php';
$bottomnavnames [$all_roles[2]][$topnavnames[3]] = 'Job Management';
$bottomnavtarget[$all_roles[2]][$topnavnames[3]] = 'job_manager.php';
$bottomnavnames [$all_roles[2]][$topnavnames[3]] = 'Resource Allocation';
$bottomnavtarget[$all_roles[2]][$topnavnames[3]] = 'resources_m.php';
$bottomnavnames [$all_roles[2]][$topnavnames[3]] = 'Referrals';
$bottomnavtarget[$all_roles[2]][$topnavnames[3]] = 'reference_m.php';
// SHOW THE ARRAYS WE JUST BUILT
echo PHP_EOL . 'BOTTOM NAV NAMES' . PHP_EOL;
var_dump($bottomnavnames);
echo PHP_EOL . 'BOTTOM NAV TARGET' . PHP_EOL;
var_dump($bottomnavtarget);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am still not sure how to loop through an array within an array and skip the outer array
You can't. Each sub array is separate to every other one.
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
This code will end up with only
$bottomnavnames [$all_roles[2]][$topnavnam
$bottomnavtarget[$all_role
being the assigned values.
Can you give the $all_roles and $topnavnames values please so I can restructure your data.