Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP arrays. There must be a simpler method to do this
    primarykey
    data
    text
    <p>I have this array in php returned from db</p> <pre> Array ( [inv_templates] => Array ( [0] => Array ( [inven_subgroup_template_id] => 1 [inven_group] => Wires [inven_subgroup] => CopperWires [inven_template_id] => 1 [inven_template_name] => CopperWires6G [constrained] => 0 [value_constraints] => [accept_range] => 2 - 16 [information] => Measured Manual ) [1] => Array ( [inven_subgroup_template_id] => 1 [inven_group] => Wires [inven_subgroup] => CopperWires [inven_template_id] => 2 [inven_template_name] => CopperWires2G [constrained] => 0 [value_constraints] => [accept_range] => 1 - 7 [information] => Measured by Automated Calipers ) ) ) </pre> <p>I need to output this kind of multidimensional stuff</p> <pre> Array ( [Wires] => Array ( [inv_group_name] => Wires [inv_subgroups] => Array ( [CopperWires] => Array ( [inv_subgroup_id] => 1 [inv_subgroup_name] => CopperWires [inv_templates] => Array ( [CopperWires6G] => Array ( [inv_name] => CopperWires6G [inv_id] => 1 ) [CopperWires2G] => Array ( [inv_name] => CopperWires2G [inv_id] => 2 ) ) ) ) ) ) </pre> <p>I currently do this stuff</p> <pre> foreach ($data['inv_templates'] as $key => $value) { $processeddata[$value['inven_group']]['inv_group_name'] = $value['inven_group']; $processeddata[$value['inven_group']]['inv_subgroups'][$value['inven_subgroup']]['inv_subgroup_id'] = $value['inven_subgroup_template_id']; $processeddata[$value['inven_group']]['inv_subgroups'][$value['inven_subgroup']]['inv_subgroup_name'] = $value['inven_subgroup']; $processeddata[$value['inven_group']]['inv_subgroups'][$value['inven_subgroup']]['inv_templates'][$value['inven_template_name']]['inv_name'] = $value['inven_template_name']; $processeddata[$value['inven_group']]['inv_subgroups'][$value['inven_subgroup']]['inv_templates'][$value['inven_template_name']]['inv_id'] = $value['inven_template_id']; } return $processeddata; </pre> <p><strong>EDIT</strong> : A var_export</p> <pre>array ( 'inv_templates' => array ( 0 => array ( 'inven_subgroup_template_id' => '1', 'inven_group' => 'Wires', 'inven_subgroup' => 'CopperWires', 'inven_template_id' => '1', 'inven_template_name' => 'CopperWires6G', 'constrained' => '0', 'value_constraints' => '', 'accept_range' => '2 - 16', 'information' => 'Measured Manual', ), 1 => array ( 'inven_subgroup_template_id' => '1', 'inven_group' => 'Wires', 'inven_subgroup' => 'CopperWires', 'inven_template_id' => '2', 'inven_template_name' => 'CopperWires6G', 'constrained' => '0', 'value_constraints' => '', 'accept_range' => '1 - 7', 'information' => 'Measured by Automated Calipers', ), ), )</pre> <p>The foreach is almost unreadable. There must be a simpler way</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload