Associate multidim array

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Associate multidim array

    I have the following table I am going to read from a database:

    ROD S_PD S_RF BZ_BRG

    0.63 8.7 38 5.7
    1.00 12.1 41.6 13.5
    1.38 13.6 45.9 13.5
    1.75 13.6 48.2 19
    2.00 15.5 69 21


    I would like to create an associateive array such that, for example, for an
    array $data:

    $data[1.38][S_RF] == 45.9

    any idea how I might do this? Thanks, Ike


    Ike Guest

  2. Similar Questions and Discussions

    1. Version 10 will not associate with swf files
      Please tell me what to do as I have tried all the window's methods. I installed today and do not have a desktop icon or an entry in All Programs....
    2. Associate a description to a jpg
      Hi! I hope somebody can help me: In my web page there are some buttons that allow to load several jpeg pictures in the same main movie,I created...
    3. Removing elements from associate array.
      Elo! I've got a problem with removing elements from associate array (php). Above you'll find a schematic structure of my array: ARRAY ------...
    4. Associate buttons with keyboard?
      I'm relatively new to flash and far from familiar with Action Script, however, is there a way to associate buttons being pressed on a webpage with...
    5. re-associate photoshop with .psd files
      hi, i have photoshop 5.5 and windows98se i recently installed irfanview 3.8 and since i did that, something strange has happened: normally...
  3. #2

    Default Re: Associate multidim array

    I specified this incorrectly - I am reading the database table in java, and
    from java, writing php code. So, what I want to do, is determine the syntax
    for specifing an associateive multidensional array such that
    $data[1.38][S_RF] == 45.9;

    I have a start on it as:

    $data = array(
    ("S_PD" => 8.7 "S_RF" => 38 "BZ_BRG" => 13.5),
    ("S_PD" => 12.1"S_RF" => 41.6"BZ_BRG" => 13.5),
    ....
    But this then gives the first index of the array as a number, and not
    associatevely, i.e. $data[2][S_RF] == 45.9; How can I specify this so that
    both indexes into the array are associative? Thanks, Ike



    "Ike" <rxv@hotmail.com> wrote in message
    news:SoIGc.10599$yy1.3790@newsread2.news.atl.earth link.net...
    > I have the following table I am going to read from a database:
    >
    > ROD S_PD S_RF BZ_BRG
    >
    > 0.63 8.7 38 5.7
    > 1.00 12.1 41.6 13.5
    > 1.38 13.6 45.9 13.5
    > 1.75 13.6 48.2 19
    > 2.00 15.5 69 21
    >
    >
    > I would like to create an associateive array such that, for example, for
    an
    > array $data:
    >
    > $data[1.38][S_RF] == 45.9
    >
    > any idea how I might do this? Thanks, Ike
    >
    >

    Ike Guest

  4. #3

    Default Re: Associate multidim array

    "Ike" <rxv@hotmail.com> wrote in message
    news:9uIGc.10605$yy1.10457@newsread2.news.atl.eart hlink.net...
    > "Ike" <rxv@hotmail.com> wrote in message
    > news:SoIGc.10599$yy1.3790@newsread2.news.atl.earth link.net...
    > > I have the following table I am going to read from a database:
    > >
    > > ROD S_PD S_RF BZ_BRG
    > >
    > > 0.63 8.7 38 5.7
    > > 1.00 12.1 41.6 13.5
    > > 1.38 13.6 45.9 13.5
    > > 1.75 13.6 48.2 19
    > > 2.00 15.5 69 21
    > >
    > >
    > > I would like to create an associateive array such that, for example, for
    > an
    > > array $data:
    > >
    > > $data[1.38][S_RF] == 45.9
    > >
    > > any idea how I might do this? Thanks, Ike
    > >
    > >
    > I specified this incorrectly - I am reading the database table in java,
    and
    > from java, writing php code. So, what I want to do, is determine the
    syntax
    > for specifing an associateive multidensional array such that
    > $data[1.38][S_RF] == 45.9;
    >
    > I have a start on it as:
    >
    > $data = array(
    > ("S_PD" => 8.7 "S_RF" => 38 "BZ_BRG" => 13.5),
    > ("S_PD" => 12.1"S_RF" => 41.6"BZ_BRG" => 13.5),
    > ...
    > But this then gives the first index of the array as a number, and not
    > associatevely, i.e. $data[2][S_RF] == 45.9; How can I specify this so that
    > both indexes into the array are associative? Thanks, Ike
    >
    Like Java, PHP has no such thing as a multi-dimensional array. Rather it has
    single-dimensional arrays. However, the value of any given array element may
    be an array. Since these arrays are actually maps (which provides the
    ability to have associative arrays), you can't have a "multi-key" array in
    the sense you are describing. In Java, you would probably create a new class
    that represented each key value you wanted and then put your entry in a Map
    object using the multi-valued key object as the key and your numeric table
    entry as the value.

    That said, you can produce one PHP array that has another PHP array as a
    value. This does require that your second key be represented as a string as
    the key to a PHP array must be an integer or a string:

    $data = array('S_PD'=> array('0.63'=>8.7, '1.00'=>12.1, '1.38'=>13.6,
    '1.75'=>13.6, '2.00'=>15.5),
    'S_RF'=> array('0.63'=>38, '1.00'=>41.6, '1.38'=>45.9,
    '1.75'=>48.2, '2.00'=>69),
    'BZ_BRG'=> array('0.63'=>5.7, '1.00'=>13.5, '1.38'=>13.5,
    '1.75'=>19, '2.00'=>21),
    );
    print_r($data);



    Virgil Green Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139