#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2005
    Posts
    2
    Rep Power
    0

    Subarray into single array


    I have a multi dimensional array.


    I want to take subarray 'style' and take the keys and put them into a new array.
    $tab[$countTab][$countNode]['style']

    here is the array:

    array(7) {
    ["Name"]=>
    string(5) "Basic"
    ["value"]=>
    string(4) "0763"
    ["category"]=>
    string(4) "Info"
    ["Order"]=>
    int(3)
    ["class"]=>
    array(3) {
    [0]=>
    string(3) "pos"
    [1]=>
    string(2) "first"
    [2]=>
    string(0) ""
    }
    ["style"]=>
    array(4) {
    ["top"]=>
    string(2) "15"
    ["left"]=>
    string(2) "20"
    ["right"]=>
    string(2) "55"
    ["width"]=>
    string(2) "200"
    }
    ["nav"]=>
    array(4) {
    ["up"]=>
    string(0) ""
    ["right"]=>
    string(0) ""
    ["down"]=>
    string(0) ""
    ["left"]=>
    string(0) ""

    how to get this result?.
    > $new_array = array( 'top' => '15', 'left' => '20', 'right' => '55', 'width' => '200')
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Um, didn't you just write that down?

    PHP Code:
    $tab[$countTab][$countNode]['style'
    That's your array (assuming $tab, $countTab and $countNode are correct). Now store it in your variable.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo