Re: does array_slice not work on multidimensional arrays?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 7 Aug 2009 17:06:45 -0600, John Butler wrote:

> does array_slice not work on multidimensional arrays?
> 
> I have one multidimensional array, and when I run it thru'    
> array_slice() nothing happens, that I can tell.
> 
> If it does not work on multidimensional arrays, what is the *simplest*  
> workaround?  (I am already working past what was budgeted for this  
> this script..  so I really want to avoid anything but the most newbie  
> of hacks to achieve this.)
> 
> //PHP Version 4.3.9

Works for me in PHP 5:

----
>cat a.php

<?php

  echo phpversion(), "\n";
  $a1 = array (array (1,2,3,4), array ('a','b','c'), array (true, false));
  $a2 = array_slice ($a1, 1, 2);
  var_dump ($a2);

>php5 a.php

5.2.5
array(2) {
  [0]=>
  array(3) {
    [0]=>
    string(1) "a"
    [1]=>
    string(1) "b"
    [2]=>
    string(1) "c"
  }
  [1]=>
  array(2) {
    [0]=>
    bool(true)
    [1]=>
    bool(false)
  }
}
----

When I first looked into array_slice, I was hoping that it
could be used to extract a "column" from a multi-dimensional
array, e.g.:

  array_slice ($a1, 1)

would result in:

  array (2, 'b', false)


This would be very useful at times, but doesn't seem
to be possible.


/Nisse

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux