Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to traverse a Multidimensional array in PHP?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 97
    Comment on it

    Multidimensinal array is the array of arrays. You can store multidimensional array as follows:

    $arr=array(
    array(1,"demo1","demo2"),
    array(1,"demo3","demo4"),
    array(1,"demo5","demo6"),
    array(1,"demo7","demo8")
    );
    

    To traverse a multidimensional array in PHP you can use the following script:

    <?php
    function get_array_elems($arrResult, $where="array"){ 
               while(list($key,$value)=each($arrResult)){ 
                     if (is_array($value)){ 
                        get_array_elems($value, $where."[$key]"); 
                     } 
                     else { 
                           for ($i=0; $i\n"; 
                           } 
                     } 
               } 
      } 
      $arr=array(
    array(1,"demo1","demo2"),
    array(2,"demo3","demo4"),
    array(3,"demo5","demo6"),
    array(4,"demo7","demo8")
    );
    get_array_elems($arr); 
    ?> 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: