473,320 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

CodeIgniter: How to traverse 2 dimentional array

245 100+
Hi,

I have had an array in the format written view and i want to traverse through & format data as per my requirement.

Expand|Select|Wrap|Line Numbers
  1. Array
  2. (
  3.     [A] => Array
  4.         (
  5.             [0] => stdClass Object
  6.                 (
  7.                     [id] => 255
  8.                     [author_name] => Jane Alexander
  9.                 )
  10.  
  11.             [1] => stdClass Object
  12.                 (
  13.                     [id] => 370
  14.                     [author_name] => Sidney Altman
  15.                 )
  16.  
  17.         )
  18.  
  19.     [b] => Array
  20.         (
  21.             [0] => stdClass Object
  22.                 (
  23.                     [id] => 1962
  24.                     [author_name] => Edwin Booth
  25.                 )
  26.  
  27.             [1] => stdClass Object
  28.                 (
  29.                     [id] => 2624
  30.                     [author_name] => Gary Burton
  31.                 )
  32.  
  33.         )
  34.  
  35.     [C] => Array
  36.         (
  37.             [0] => stdClass Object
  38.                 (
  39.                     [id] => 2747
  40.                     [author_name] => Timothy F. Cahill
  41.                 )
  42.  
  43.             [1] => stdClass Object
  44.                 (
  45.                     [id] => 3384
  46.                     [author_name] => Jean Chretien
  47.                 )
  48.  
  49.         )
  50.  
  51.     [D] => Array
  52.         (
  53.             [0] => stdClass Object
  54.                 (
  55.                     [id] => 4682
  56.                     [author_name] => Ted Dexter
  57.                 )
  58.  
  59.             [1] => stdClass Object
  60.                 (
  61.                     [id] => 5088
  62.                     [author_name] => Ian Dury
  63.                 )
  64.  
  65.         )
  66.  
  67.     [E] => Array
  68.         (
  69.             [0] => stdClass Object
  70.                 (
  71.                     [id] => 5268
  72.                     [author_name] => Alfred Eisenstaedt
  73.                 )
  74.  
  75.             [1] => stdClass Object
  76.                 (
  77.                     [id] => 5296
  78.                     [author_name] => Mircea Eliade
  79.                 )
  80.  
  81.         )
  82.  
  83.     [F] => Array
  84.         (
  85.             [0] => stdClass Object
  86.                 (
  87.                     [id] => 6084
  88.                     [author_name] => Kay Francis
  89.                 )
  90.  
  91.             [1] => stdClass Object
  92.                 (
  93.                     [id] => 5845
  94.                     [author_name] => Robert J. Flaherty
  95.                 )
  96.  
  97.         )
  98.  
  99.     [G] => Array
  100.         (
  101.             [0] => stdClass Object
  102.                 (
  103.                     [id] => 6928
  104.                     [author_name] => James Grainger
  105.                 )
  106.  
  107.             [1] => stdClass Object
  108.                 (
  109.                     [id] => 6353
  110.                     [author_name] => Jan Garbarek
  111.                 )
  112.  
  113.         )
  114.  
  115.     [H] => Array
  116.         (
  117.             [0] => stdClass Object
  118.                 (
  119.                     [id] => 8227
  120.                     [author_name] => M. F. Husain
  121.                 )
  122.  
  123.             [1] => stdClass Object
  124.                 (
  125.                     [id] => 7840
  126.                     [author_name] => John Hoeven
  127.                 )
  128.  
  129.         )
  130.  
  131.     [i] => Array
  132.         (
  133.             [0] => stdClass Object
  134.                 (
  135.                     [id] => 8320
  136.                     [author_name] => Helge Ingstad
  137.                 )
  138.  
  139.             [1] => stdClass Object
  140.                 (
  141.                     [id] => 8299
  142.                     [author_name] => Greg Iles
  143.                 )
  144.  
  145.         )
  146.  
  147.     [J] => Array
  148.         (
  149.             [0] => stdClass Object
  150.                 (
  151.                     [id] => 8543
  152.                     [author_name] => Ron Jaworski
  153.                 )
  154.  
  155.             [1] => stdClass Object
  156.                 (
  157.                     [id] => 8394
  158.                     [author_name] => Terrence J
  159.                 )
  160.  
  161.         )
  162.  
  163.     [K] => Array
  164.         (
  165.             [0] => stdClass Object
  166.                 (
  167.                     [id] => 9512
  168.                     [author_name] => Harmony Korine
  169.                 )
  170.  
  171.             [1] => stdClass Object
  172.                 (
  173.                     [id] => 9245
  174.                     [author_name] => Ayatollah Khomeini
  175.                 )
  176.  
  177.         )
  178.  
  179.     [L] => Array
  180.         (
  181.             [0] => stdClass Object
  182.                 (
  183.                     [id] => 10135
  184.                     [author_name] => Joshua Leonard
  185.                 )
  186.  
  187.             [1] => stdClass Object
  188.                 (
  189.                     [id] => 10035
  190.                     [author_name] => Christopher Lee
  191.                 )
  192.  
  193.         )
  194.  
  195.     [M] => Array
  196.         (
  197.             [0] => stdClass Object
  198.                 (
  199.                     [id] => 11010
  200.                     [author_name] => Juliet Marillier
  201.                 )
  202.  
  203.             [1] => stdClass Object
  204.                 (
  205.                     [id] => 11743
  206.                     [author_name] => James Mill
  207.                 )
  208.  
  209.         )
  210.  
  211.     [N] => Array
  212.         (
  213.             [0] => stdClass Object
  214.                 (
  215.                     [id] => 12474
  216.                     [author_name] => Navid Negahban
  217.                 )
  218.  
  219.             [1] => stdClass Object
  220.                 (
  221.                     [id] => 12480
  222.                     [author_name] => Sam Neill
  223.                 )
  224.  
  225.         )
  226.  
  227.     [O] => Array
  228.         (
  229.             [0] => stdClass Object
  230.                 (
  231.                     [id] => 12792
  232.                     [author_name] => Denis O'Hare
  233.                 )
  234.  
  235.             [1] => stdClass Object
  236.                 (
  237.                     [id] => 12923
  238.                     [author_name] => Renee Olstead
  239.                 )
  240.  
  241.         )
  242.  
  243.     [P] => Array
  244.         (
  245.             [0] => stdClass Object
  246.                 (
  247.                     [id] => 13672
  248.                     [author_name] => Tracy Pollan
  249.                 )
  250.  
  251.             [1] => stdClass Object
  252.                 (
  253.                     [id] => 13181
  254.                     [author_name] => C. Northcote Parkinson
  255.                 )
  256.  
  257.         )
  258.  
  259.     [Q] => Array
  260.         (
  261.             [0] => stdClass Object
  262.                 (
  263.                     [id] => 13930
  264.                     [author_name] => Randy Quaid
  265.                 )
  266.  
  267.             [1] => stdClass Object
  268.                 (
  269.                     [id] => 13929
  270.                     [author_name] => Jack Quaid
  271.                 )
  272.  
  273.         )
  274.  
  275.     [R] => Array
  276.         (
  277.             [0] => stdClass Object
  278.                 (
  279.                     [id] => 14305
  280.                     [author_name] => Buddy Rice
  281.                 )
  282.  
  283.             [1] => stdClass Object
  284.                 (
  285.                     [id] => 14527
  286.                     [author_name] => Jerry Robinson
  287.                 )
  288.  
  289.         )
  290.  
  291.     [S] => Array
  292.         (
  293.             [0] => stdClass Object
  294.                 (
  295.                     [id] => 15766
  296.                     [author_name] => Bill Sienkiewicz
  297.                 )
  298.  
  299.             [1] => stdClass Object
  300.                 (
  301.                     [id] => 16302
  302.                     [author_name] => Willie Stargell
  303.                 )
  304.  
  305.         )
  306.  
  307.     [T] => Array
  308.         (
  309.             [0] => stdClass Object
  310.                 (
  311.                     [id] => 17039
  312.                     [author_name] => Howard Thurston
  313.                 )
  314.  
  315.             [1] => stdClass Object
  316.                 (
  317.                     [id] => 17234
  318.                     [author_name] => Lynne Truss
  319.                 )
  320.  
  321.         )
  322.  
  323.     [u] => Array
  324.         (
  325.             [0] => stdClass Object
  326.                 (
  327.                     [id] => 17330
  328.                     [author_name] => Kohei Uchimura
  329.                 )
  330.  
  331.             [1] => stdClass Object
  332.                 (
  333.                     [id] => 17350
  334.                     [author_name] => Bjorn Ulvaeus
  335.                 )
  336.  
  337.         )
  338.  
  339.     [V] => Array
  340.         (
  341.             [0] => stdClass Object
  342.                 (
  343.                     [id] => 17530
  344.                     [author_name] => Tito Vilanova
  345.                 )
  346.  
  347.             [1] => stdClass Object
  348.                 (
  349.                     [id] => 17476
  350.                     [author_name] => Terry Venables
  351.                 )
  352.  
  353.         )
  354.  
  355.     [W] => Array
  356.         (
  357.             [0] => stdClass Object
  358.                 (
  359.                     [id] => 18311
  360.                     [author_name] => Bruce Willis
  361.                 )
  362.  
  363.             [1] => stdClass Object
  364.                 (
  365.                     [id] => 18407
  366.                     [author_name] => Dave Winer
  367.                 )
  368.  
  369.         )
  370.  
  371.     [X] => Array
  372.         (
  373.             [0] => stdClass Object
  374.                 (
  375.                     [id] => 18634
  376.                     [author_name] => Francis Xavier
  377.                 )
  378.  
  379.             [1] => stdClass Object
  380.                 (
  381.                     [id] => 18642
  382.                     [author_name] => Lu Xun
  383.                 )
  384.  
  385.         )
  386.  
  387.     [Y] => Array
  388.         (
  389.             [0] => stdClass Object
  390.                 (
  391.                     [id] => 18673
  392.                     [author_name] => Adam Yauch
  393.                 )
  394.  
  395.             [1] => stdClass Object
  396.                 (
  397.                     [id] => 18660
  398.                     [author_name] => Yanni
  399.                 )
  400.  
  401.         )
  402.  
  403.     [Z] => Array
  404.         (
  405.             [0] => stdClass Object
  406.                 (
  407.                     [id] => 18831
  408.                     [author_name] => Khaleda Zia
  409.                 )
  410.  
  411.             [1] => stdClass Object
  412.                 (
  413.                     [id] => 18883
  414.                     [author_name] => Stefan Zweig
  415.                 )
  416.  
  417.         )
  418.  
  419. )
  420.  
Can some one guide me how can i traverse this CI view....!
Aug 22 '13 #1
1 1990
neovantage
245 100+
Guys,
I have done it myself. This is my code for future reference.


Expand|Select|Wrap|Line Numbers
  1. <?php
  2. foreach($alphabets as $key => $val){
  3.    if(is_array($val)){
  4.        foreach($val as $subval){
  5.            $character[] = $key;
  6.            $author_id[] = $subval->id;
  7.            $author_name[] = $subval->author_name;
  8.        }
  9.    }
  10. }
  11. ?>
  12.  
Aug 23 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Cedric Baelemans | last post by:
Hi, I try to store a two-dimentional array in a session variable. When I do the same with a one-dimentional array, it works fine, but with a two-dimentional array it fails. Is this not possible?...
8
by: Al | last post by:
I'd like to declare (in a Matrix class) a two-dimentional array with user-defined coordinates. The constructor is: Matrix(int c, int l): col(c), lin(l), a(new float) {} the compiler says 'lin'...
1
by: rkmoray | last post by:
I have created a Multi Dimentional array, but having problems filling it. int mCount=0; mCount=ds.Tables.Rows.Count; string arrayppsa = new string ; DataTable myDataTable=ds.Tables;...
0
by: rkmoray | last post by:
I have created a Multi Dimentional array, but having problems filling it. int mCount=0; mCount=ds.Tables.Rows.Count; string arrayppsa = new string ; DataTable myDataTable=ds.Tables;...
0
by: Max M. Power | last post by:
I'm getting an InvalidOperationException calling Invoke with a method parameter object array that contains a two dimentional string array. More stack trace output below: // Create two...
2
by: Icarus27 | last post by:
Hello, I am making a program that runs off of a two dimentional array but I have made it into a game called MouseBot. I am trying to make the game so that you can move the mouse until you get the...
3
by: cmdolcet69 | last post by:
I can the following error message "value of type byte cannot be converted to 1-dimentional array of byte" when i execute this line of code: moRS232.Write(Packet(i)) it underline the packet(i)...
9
by: Srinu | last post by:
Hi All, We know the following facts, 1. A two dimentional arrays in C is stored similar to a single dimentional array. 2. * is the dereference operator that gives value at address denoted by...
3
by: neovantage | last post by:
Hey all, I need to sort 2 dimentional array. My data is in this form arrayName = decimal value say 1 arrayName = name say abc arrayName = decimal value say 2 arrayName = name say def...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.