Johdanto moniulotteiseen taulukkoon PHP: ssä

Moniulotteinen taulukko ei ole mitään erikoista, mutta toisen taulukon sisällä oleva taulukko. Jokaisessa taulukon hakemistossa on toinen taulukko yhden elementin sijasta, joka taas voi osoittaa toiseen taulukkoon tai tiettyihin elementteihin. näihin ryhmän sisällä oleviin alimatriiseihin päästään käyttämällä useita ulottuvuuksia alkaen ulommasta ryhmästä ja siirtyen kohti sisäistä ryhmää. Mitat ovat pohjimmiltaan indeksejä, joita tarvitaan arvon käyttämiseen tai säilyttämiseen tietyssä taulukon kohdassa. Php: n moniulotteisia matriiseja käytetään erittäin paljon reaaliaikaisissa sovelluksissa, mutta on melko hankala käsitellä niitä verrattuna yhden ulottuvuuden matriiseihin, koska hakasulkeissa on useita ominaisuuksia ja monimutkaisuus, jotta voidaan työskennellä niiden kanssa, joko käyttää tai tallentaa arvoja tietty indeksi, silmukoiden käyttö vaaditaan.

Moniulotteisen taulukon syntaksi PHP: ssä

Alla on esitetty moniulotteisten taulukkojen yleinen syntaksi PHP: ssä. Vaikka PHP: n moniulotteiset taulukot voivat olla 2D, 3D, 4D ja niin edelleen. Mitä enemmän ulotteinen taulukko on, sitä vaikeampaa on hallita niitä ja enemmän haarukoita lisätään taulukon nimen eteen.

2D-taulukon syntaksi:

array(
array(element1, element2, elements3, …),
array(element1, element2, elements3, …),
… so on
)

3D-taulukon syntaksi:

array(
array (
array(element1, element2, elements3, …),
array(element1, element2, elements3, …),
… so on
),
array (
array(element1, element2, elements3, …),
array(element1, element2, elements3, …),
… so on
),
… so on
)

Kuinka julistaa moniulotteiset taulukot PHP: ssä?

PHP Mahdollistaa sen moniulotteisten ryhmien indeksoinnin tai assosiaation. Assosiatiiviset taulukot ovat vuorovaikutteisempia indeksoituihin. PHP antaa hyvin yksinkertaisen tavan julistaa moniulotteinen taulukko PHP: ssä avainsanalla 'array'. Jotta voidaan julistaa taulukko toisen taulukon sisällä, meidän on lisättävä avainsana 'taulukko' ja sitten sen taulukon elementit.

1. 2D-taulukon ilmoitus PHP: ssä

Koodi:

<_?php
$employee_details = array();
$employee_details( ) = array(“Ram”, “Agra”, “Sr. Engineer”);
$employee_details( ) = array(“Raghav”, “Delhi”, “Jr. Engineer”);
?>

TAI

<_?php
$employee_details = array(
array(“Ram”, “Agra”, “Sr. Engineer”),
array(“Raghav”, “Delhi”, “Jr. Engineer”),
);
?>

Toista yllä esitettyä menetelmää käytetään yleisesti, koska se on melko helppo ymmärtää.

2. 3D-taulukon ilmoitus PHP: ssä

Koodi:

<_?php
/* Simplest way to declare a 3D array in Php in an indexed manner */
$item_details = array(
array(
array (“item1”, “abc”, 100)),
array (“item2”, “bcd”, 200)),
array (“item3”, “def”, 300)),
),
array(
array (“item4”, “abc4”, 100)),
array (“item5, “bcd5”, 200)),
array (“item6”, “def6”, 300)),
),
);
?>

Yllä oleva ilmoitus on puhtaasti indeksoitu yksi 3D-matriiseista, koska assosiointiin ei käytetä avain-arvo-pareja.

Kuinka alustaa moniulotteinen taulukko PHP: ssä?

Moniulotteisen taulukon alustaminen tarkoittaa arvojen tai elementtien osoittamista taulukon tiettyyn sijaintiin tai indekseihin. Moniulotteisen taulukon alustaminen PHP: ssä on melko helppoa kuin julistaminen. Ainoa asia, joka pitää mielessä, on kiinnikkeiden käyttö alikokojen alustaessa. Alustaessasi arvoja moniulotteisessa taulukossa, pääryhmä voi olla indeksoitu tai assosiatiivinen, alla olevassa esimerkissä pääryhmä on assosiatiivinen, jolla on näppäimet kuten Levis, Lee, Denizen, jne.,

1. 2D-taulukon alustaminen PHP: ssä

Koodi:

<_?php
/* It is a multidimensional 2D array of clothes in which the main array holds another arrays of having 2 elements like cloth type and quantity */
/* It is associative kind of array having the data in the form of key => value pairs. So the data at the inner subarray is represented as associated by the key element.*/
$clothes = array(
“Levis” => array(
“Cloth_type” => “jeans”,
“Quantity” => 20
),
“Pepe” => array(
“Cloth_type” => “jeans”,
“Quantity” => 100
),
“Lee” => array(
“Cloth_type” => “tshirts”,
“Quantity” => 50
),
“Denizen” => array(
“Cloth_type” => “tops”,
“Quantity” => 80
)
);
?>

2. 3D-taulukon alustaminen PHP: ssä

3D-taulukkojen alustus on sama kuin 2D-taulukot, ainoa ero näiden välillä on mitat. 3D-taulukko vaatii vielä yhden hakemiston sen alustamiseksi kuin 2D-taulukko. Matriisin mittojen lukumäärä kasvaa, indikaattorien lukumäärä myös sen alustamiseksi kasvaa. Oheisessa esimerkissä pääryhmä on yksinkertainen indeksoitu taulukko, jolla on itsessään alaryhmiä. Voimme tehdä myös alla olevan esimerkin pääryhmän assosiatiiviseksi, kuten olemme tehneet 2D-ryhmässä avaimen kanssa tuotemerkkinä, mikä helpottaa asiakkaan ymmärtämistä sitä käytettäessä ja tallennettaessa.

Koodi:

<_?php
/* In this there is a 3D array of clothes in which each element have an array of cloth type, brand and quantity of that particular brand. Each brand has different quantity and cloth type.*/
$clothes = array(
array(
array(
“Brand” => “Levis”,
“Cloth_type” => “jeans”,
“Quantity” => 20
),
array(
“Brand” => “Levis”,
“Cloth_type” => “Tops”,
“Quantity” => 100
)
),
array(
array(
“Brand” => “Lee”,
“Cloth_type” => “jeans”,
“Quantity” => 50
),
array(
“Brand” => “Lee”,
“Cloth_type” => “tops”,
“Quantity” => 80
)
),
);
?>

Moniulotteisten ryhmien käyttö PHP: ssä

Moniulotteisten taulukkojen käyttö PHP: ssä on hyvin yksinkertaista, ja se tapahtuu käyttämällä joko joko tai jokaiselle silmukalle, joka on PHP: ssä yleisesti käytettyjä silmukoita. Indeksoiduissa matriiseissa taulukkoelementteihin voidaan päästä normaalisti käyttämällä rivin ja sarakkeen numeroa samoin kuin muut kielet, kuten C, Java, jne. (Arr (rivinumero) (sarake_numero))

Assosiatiivisten taulukkojen tapauksessa moniulotteisen taulukon elementeille pääsy suoritetaan avain- ja arvopareilla (avain => arvo). Vaikka elementteihin päästäänkin yksinkertaisen tai jokaiselle silmukalle kautta. Katso alla olevasta esimerkistä selkeä käsitys moniulotteisten ryhmien elementtien käytöstä.

Moniulotteisen taulukon tyypit PHP: ssä

Ei ole erityistä tilaa, johon asti moniulotteiset taulukot voivat esiintyä PHP: ssä. Se riippuu tietystä tilanteesta ja skenaariosta. Matriisin mitat vaihtelevat vastaavasti. Tavallisesti ohjelmoijat käyttävät 2D- ja 3D-taulukkoja, koska 3D-taulukkojen jälkeen on vähän vaikea hallita niitä.

Kuten olemme ymmärtäneet moniulotteisten taulukkojen ilmoittamisen, alustamisen ja käytön PHP: ssä, on aika nopeaa selitystä esimerkeillä.

1. 2D-taulukko PHP: ssä

2D-taulukot ovat periaatteessa taulukko toisen taulukon sisällä. Mieti, että käyttäjällä on 10 kirjaa ja jokaisella teoksella on eri nimi, hinta, tyyppi. Tässä tapauksessa ohjelmoija voi luoda joukon kirjanumeroita ja jokaisessa pääryhmän elementissä on taulukko, joka sisältää kirjan yksityiskohdat, kuten nimi, hinta ja tyyppi.

Koodi:



/* Multidimensional 2D array for 4 books and each book having a different array containing book name, cost and type. */
$books = array(
array("Fiction ", "Action and Adventure ", 800),
array("Fiction ", "Anthology ", 1000),
array("Non- Fiction ", "Biography ", 600),
array("Non- Fiction ", "Cook Book ", 900)
);
/* Accessing of a 2D array with the row_number and column_number */
for ($row_num = 0; $row_num < 4; $row_num++) (
echo "
<_?php


/* Multidimensional 2D array for 4 books and each book having a different array containing book name, cost and type. */
$books = array(
array("Fiction ", "Action and Adventure ", 800),
array("Fiction ", "Anthology ", 1000),
array("Non- Fiction ", "Biography ", 600),
array("Non- Fiction ", "Cook Book ", 900)
);
/* Accessing of a 2D array with the row_number and column_number */
for ($row_num = 0; $row_num < 4; $row_num++) (
echo "

Kirjan numero on $ row_num

";
kohteelle ($ col_num = 0; $ col_num <3; $ col_num ++) (
// Tiettyyn elementtiin pääsy 2D-taulukossa
echo $ kirjat ($ row_num) ($ col_num);
)
kaiku "
";
)
?>

lähtö:

2. 3D-taulukko PHP: ssä

3D-taulukot ovat jatkoa 2D-ryhmille. 3D-taulukot sisältävät vielä yhden ulottuvuuden ja tarjoavat mahdollisuuden lisätä yksityiskohtaisempia tietoja. Mieti työntekijäryhmää, jossa työntekijällä on nimi, yritys ja vuosi ja jokaisella työntekijällä on yritysprofiili, jolla on tunnukset, taidot ja profiili. Jokaisella työntekijällä on henkilötiedot myös kaupungin, osavaltion ja maan yksityiskohdat. Tilauksen säilyttämistä varten tarvitaan yllä oleva 3D-taulukko.

Koodi:



$Employee = array(array(array("name", "company", "year"),
array("id", "skills", "profile"),
array("city", "state", "country")
),
/* array to store the name, company and year of employee*/
array(array("jiya", "Infosys", 2016),
array("ram", "ola", 2017)
),
/* array to store the id, skills and profile of employees */
array(array("E101", "PHP", "developer"),
array("E103", "mysql", "DBA")
),
/* array to store the city, state and country of employees */
array(array("Bangalore", "Karnataka", "India"),
array("San Francisco", "California", "USA")
)
);
?>
echo " ";
for ( $outermost = 0; $outermost < 3; $outermost++ )
(
echo " The outermost number $outermost";
echo " ";
for ( $row_num = 0; $row_num < 2; $row_num++ )
(
echo " Now displaying the row number $row_num";
echo " ";
for ( $col_num = 0; $col_num < 3; $col_num++ )
(
// accessing the array elements in a 3D array
echo " ".$Employee($outermost)($row_num)($col_num)." ";
)
echo " ";
echo " ";
)
echo " ";
echo " ";
)
echo " ";
?>
<_?php


$Employee = array(array(array("name", "company", "year"),
array("id", "skills", "profile"),
array("city", "state", "country")
),
/* array to store the name, company and year of employee*/
array(array("jiya", "Infosys", 2016),
array("ram", "ola", 2017)
),
/* array to store the id, skills and profile of employees */
array(array("E101", "PHP", "developer"),
array("E103", "mysql", "DBA")
),
/* array to store the city, state and country of employees */
array(array("Bangalore", "Karnataka", "India"),
array("San Francisco", "California", "USA")
)
);
?>
echo " ";
for ( $outermost = 0; $outermost < 3; $outermost++ )
(
echo " The outermost number $outermost";
echo " ";
for ( $row_num = 0; $row_num < 2; $row_num++ )
(
echo " Now displaying the row number $row_num";
echo " ";
for ( $col_num = 0; $col_num < 3; $col_num++ )
(
// accessing the array elements in a 3D array
echo " ".$Employee($outermost)($row_num)($col_num)." ";
)
echo " ";
echo " ";
)
echo " ";
echo " ";
)
echo " ";
?>
<_?php


$Employee = array(array(array("name", "company", "year"),
array("id", "skills", "profile"),
array("city", "state", "country")
),
/* array to store the name, company and year of employee*/
array(array("jiya", "Infosys", 2016),
array("ram", "ola", 2017)
),
/* array to store the id, skills and profile of employees */
array(array("E101", "PHP", "developer"),
array("E103", "mysql", "DBA")
),
/* array to store the city, state and country of employees */
array(array("Bangalore", "Karnataka", "India"),
array("San Francisco", "California", "USA")
)
);
?>
echo " ";
for ( $outermost = 0; $outermost < 3; $outermost++ )
(
echo " The outermost number $outermost";
echo " ";
for ( $row_num = 0; $row_num < 2; $row_num++ )
(
echo " Now displaying the row number $row_num";
echo " ";
for ( $col_num = 0; $col_num < 3; $col_num++ )
(
// accessing the array elements in a 3D array
echo " ".$Employee($outermost)($row_num)($col_num)." ";
)
echo " ";
echo " ";
)
echo " ";
echo " ";
)
echo " ";
?>



    $Employee = array(array(array("name", "company", "year"),
    array("id", "skills", "profile"),
    array("city", "state", "country")
    ),
    /* array to store the name, company and year of employee*/
    array(array("jiya", "Infosys", 2016),
    array("ram", "ola", 2017)
    ),
    /* array to store the id, skills and profile of employees */
    array(array("E101", "PHP", "developer"),
    array("E103", "mysql", "DBA")
    ),
    /* array to store the city, state and country of employees */
    array(array("Bangalore", "Karnataka", "India"),
    array("San Francisco", "California", "USA")
    )
    );
    ?>
    echo " ";
    for ( $outermost = 0; $outermost < 3; $outermost++ )
    (
    echo " The outermost number $outermost";
    echo " ";
    for ( $row_num = 0; $row_num < 2; $row_num++ )
    (
    echo " Now displaying the row number $row_num";
    echo " ";
    for ( $col_num = 0; $col_num < 3; $col_num++ )
    (
    // accessing the array elements in a 3D array
    echo " ".$Employee($outermost)($row_num)($col_num)." ";
    )
    echo " ";
    echo " ";
    )
    echo " ";
    echo " ";
    )
    echo " ";
    ?>


  • $Employee = array(array(array("name", "company", "year"),
    array("id", "skills", "profile"),
    array("city", "state", "country")
    ),
    /* array to store the name, company and year of employee*/
    array(array("jiya", "Infosys", 2016),
    array("ram", "ola", 2017)
    ),
    /* array to store the id, skills and profile of employees */
    array(array("E101", "PHP", "developer"),
    array("E103", "mysql", "DBA")
    ),
    /* array to store the city, state and country of employees */
    array(array("Bangalore", "Karnataka", "India"),
    array("San Francisco", "California", "USA")
    )
    );
    ?>
    echo " ";
    for ( $outermost = 0; $outermost < 3; $outermost++ )
    (
    echo " The outermost number $outermost";
    echo " ";
    for ( $row_num = 0; $row_num < 2; $row_num++ )
    (
    echo " Now displaying the row number $row_num";
    echo " ";
    for ( $col_num = 0; $col_num < 3; $col_num++ )
    (
    // accessing the array elements in a 3D array
    echo " ".$Employee($outermost)($row_num)($col_num)." ";
    )
    echo " ";
    echo " ";
    )
    echo " ";
    echo " ";
    )
    echo " ";
    ?>


      $Employee = array(array(array("name", "company", "year"),
      array("id", "skills", "profile"),
      array("city", "state", "country")
      ),
      /* array to store the name, company and year of employee*/
      array(array("jiya", "Infosys", 2016),
      array("ram", "ola", 2017)
      ),
      /* array to store the id, skills and profile of employees */
      array(array("E101", "PHP", "developer"),
      array("E103", "mysql", "DBA")
      ),
      /* array to store the city, state and country of employees */
      array(array("Bangalore", "Karnataka", "India"),
      array("San Francisco", "California", "USA")
      )
      );
      ?>
      echo " ";
      for ( $outermost = 0; $outermost < 3; $outermost++ )
      (
      echo " The outermost number $outermost";
      echo " ";
      for ( $row_num = 0; $row_num < 2; $row_num++ )
      (
      echo " Now displaying the row number $row_num";
      echo " ";
      for ( $col_num = 0; $col_num < 3; $col_num++ )
      (
      // accessing the array elements in a 3D array
      echo " ".$Employee($outermost)($row_num)($col_num)." ";
      )
      echo " ";
      echo " ";
      )
      echo " ";
      echo " ";
      )
      echo " ";
      ?>


    • $Employee = array(array(array("name", "company", "year"),
      array("id", "skills", "profile"),
      array("city", "state", "country")
      ),
      /* array to store the name, company and year of employee*/
      array(array("jiya", "Infosys", 2016),
      array("ram", "ola", 2017)
      ),
      /* array to store the id, skills and profile of employees */
      array(array("E101", "PHP", "developer"),
      array("E103", "mysql", "DBA")
      ),
      /* array to store the city, state and country of employees */
      array(array("Bangalore", "Karnataka", "India"),
      array("San Francisco", "California", "USA")
      )
      );
      ?>
      echo " ";
      for ( $outermost = 0; $outermost < 3; $outermost++ )
      (
      echo " The outermost number $outermost";
      echo " ";
      for ( $row_num = 0; $row_num < 2; $row_num++ )
      (
      echo " Now displaying the row number $row_num";
      echo " ";
      for ( $col_num = 0; $col_num < 3; $col_num++ )
      (
      // accessing the array elements in a 3D array
      echo " ".$Employee($outermost)($row_num)($col_num)." ";
      )
      echo " ";
      echo " ";
      )
      echo " ";
      echo " ";
      )
      echo " ";
      ?>


        $Employee = array(array(array("name", "company", "year"),
        array("id", "skills", "profile"),
        array("city", "state", "country")
        ),
        /* array to store the name, company and year of employee*/
        array(array("jiya", "Infosys", 2016),
        array("ram", "ola", 2017)
        ),
        /* array to store the id, skills and profile of employees */
        array(array("E101", "PHP", "developer"),
        array("E103", "mysql", "DBA")
        ),
        /* array to store the city, state and country of employees */
        array(array("Bangalore", "Karnataka", "India"),
        array("San Francisco", "California", "USA")
        )
        );
        ?>
        echo " ";
        for ( $outermost = 0; $outermost < 3; $outermost++ )
        (
        echo " The outermost number $outermost";
        echo " ";
        for ( $row_num = 0; $row_num < 2; $row_num++ )
        (
        echo " Now displaying the row number $row_num";
        echo " ";
        for ( $col_num = 0; $col_num < 3; $col_num++ )
        (
        // accessing the array elements in a 3D array
        echo " ".$Employee($outermost)($row_num)($col_num)." ";
        )
        echo " ";
        echo " ";
        )
        echo " ";
        echo " ";
        )
        echo " ";
        ?>


      • $Employee = array(array(array("name", "company", "year"),
        array("id", "skills", "profile"),
        array("city", "state", "country")
        ),
        /* array to store the name, company and year of employee*/
        array(array("jiya", "Infosys", 2016),
        array("ram", "ola", 2017)
        ),
        /* array to store the id, skills and profile of employees */
        array(array("E101", "PHP", "developer"),
        array("E103", "mysql", "DBA")
        ),
        /* array to store the city, state and country of employees */
        array(array("Bangalore", "Karnataka", "India"),
        array("San Francisco", "California", "USA")
        )
        );
        ?>
        echo " ";
        for ( $outermost = 0; $outermost < 3; $outermost++ )
        (
        echo " The outermost number $outermost";
        echo " ";
        for ( $row_num = 0; $row_num < 2; $row_num++ )
        (
        echo " Now displaying the row number $row_num";
        echo " ";
        for ( $col_num = 0; $col_num < 3; $col_num++ )
        (
        // accessing the array elements in a 3D array
        echo " ".$Employee($outermost)($row_num)($col_num)." ";
        )
        echo " ";
        echo " ";
        )
        echo " ";
        echo " ";
        )
        echo " ";
        ?>


      • $Employee = array(array(array("name", "company", "year"),
        array("id", "skills", "profile"),
        array("city", "state", "country")
        ),
        /* array to store the name, company and year of employee*/
        array(array("jiya", "Infosys", 2016),
        array("ram", "ola", 2017)
        ),
        /* array to store the id, skills and profile of employees */
        array(array("E101", "PHP", "developer"),
        array("E103", "mysql", "DBA")
        ),
        /* array to store the city, state and country of employees */
        array(array("Bangalore", "Karnataka", "India"),
        array("San Francisco", "California", "USA")
        )
        );
        ?>
        echo " ";
        for ( $outermost = 0; $outermost < 3; $outermost++ )
        (
        echo " The outermost number $outermost";
        echo " ";
        for ( $row_num = 0; $row_num < 2; $row_num++ )
        (
        echo " Now displaying the row number $row_num";
        echo " ";
        for ( $col_num = 0; $col_num < 3; $col_num++ )
        (
        // accessing the array elements in a 3D array
        echo " ".$Employee($outermost)($row_num)($col_num)." ";
        )
        echo " ";
        echo " ";
        )
        echo " ";
        echo " ";
        )
        echo " ";
        ?>


      $Employee = array(array(array("name", "company", "year"),
      array("id", "skills", "profile"),
      array("city", "state", "country")
      ),
      /* array to store the name, company and year of employee*/
      array(array("jiya", "Infosys", 2016),
      array("ram", "ola", 2017)
      ),
      /* array to store the id, skills and profile of employees */
      array(array("E101", "PHP", "developer"),
      array("E103", "mysql", "DBA")
      ),
      /* array to store the city, state and country of employees */
      array(array("Bangalore", "Karnataka", "India"),
      array("San Francisco", "California", "USA")
      )
      );
      ?>
      echo " ";
      for ( $outermost = 0; $outermost < 3; $outermost++ )
      (
      echo " The outermost number $outermost";
      echo " ";
      for ( $row_num = 0; $row_num < 2; $row_num++ )
      (
      echo " Now displaying the row number $row_num";
      echo " ";
      for ( $col_num = 0; $col_num < 3; $col_num++ )
      (
      // accessing the array elements in a 3D array
      echo " ".$Employee($outermost)($row_num)($col_num)." ";
      )
      echo " ";
      echo " ";
      )
      echo " ";
      echo " ";
      )
      echo " ";
      ?>


    • $Employee = array(array(array("name", "company", "year"),
      array("id", "skills", "profile"),
      array("city", "state", "country")
      ),
      /* array to store the name, company and year of employee*/
      array(array("jiya", "Infosys", 2016),
      array("ram", "ola", 2017)
      ),
      /* array to store the id, skills and profile of employees */
      array(array("E101", "PHP", "developer"),
      array("E103", "mysql", "DBA")
      ),
      /* array to store the city, state and country of employees */
      array(array("Bangalore", "Karnataka", "India"),
      array("San Francisco", "California", "USA")
      )
      );
      ?>
      echo " ";
      for ( $outermost = 0; $outermost < 3; $outermost++ )
      (
      echo " The outermost number $outermost";
      echo " ";
      for ( $row_num = 0; $row_num < 2; $row_num++ )
      (
      echo " Now displaying the row number $row_num";
      echo " ";
      for ( $col_num = 0; $col_num < 3; $col_num++ )
      (
      // accessing the array elements in a 3D array
      echo " ".$Employee($outermost)($row_num)($col_num)." ";
      )
      echo " ";
      echo " ";
      )
      echo " ";
      echo " ";
      )
      echo " ";
      ?>


    $Employee = array(array(array("name", "company", "year"),
    array("id", "skills", "profile"),
    array("city", "state", "country")
    ),
    /* array to store the name, company and year of employee*/
    array(array("jiya", "Infosys", 2016),
    array("ram", "ola", 2017)
    ),
    /* array to store the id, skills and profile of employees */
    array(array("E101", "PHP", "developer"),
    array("E103", "mysql", "DBA")
    ),
    /* array to store the city, state and country of employees */
    array(array("Bangalore", "Karnataka", "India"),
    array("San Francisco", "California", "USA")
    )
    );
    ?>
    echo " ";
    for ( $outermost = 0; $outermost < 3; $outermost++ )
    (
    echo " The outermost number $outermost";
    echo " ";
    for ( $row_num = 0; $row_num < 2; $row_num++ )
    (
    echo " Now displaying the row number $row_num";
    echo " ";
    for ( $col_num = 0; $col_num < 3; $col_num++ )
    (
    // accessing the array elements in a 3D array
    echo " ".$Employee($outermost)($row_num)($col_num)." ";
    )
    echo " ";
    echo " ";
    )
    echo " ";
    echo " ";
    )
    echo " ";
    ?>


  • $Employee = array(array(array("name", "company", "year"),
    array("id", "skills", "profile"),
    array("city", "state", "country")
    ),
    /* array to store the name, company and year of employee*/
    array(array("jiya", "Infosys", 2016),
    array("ram", "ola", 2017)
    ),
    /* array to store the id, skills and profile of employees */
    array(array("E101", "PHP", "developer"),
    array("E103", "mysql", "DBA")
    ),
    /* array to store the city, state and country of employees */
    array(array("Bangalore", "Karnataka", "India"),
    array("San Francisco", "California", "USA")
    )
    );
    ?>
    echo " ";
    for ( $outermost = 0; $outermost < 3; $outermost++ )
    (
    echo " The outermost number $outermost";
    echo " ";
    for ( $row_num = 0; $row_num < 2; $row_num++ )
    (
    echo " Now displaying the row number $row_num";
    echo " ";
    for ( $col_num = 0; $col_num < 3; $col_num++ )
    (
    // accessing the array elements in a 3D array
    echo " ".$Employee($outermost)($row_num)($col_num)." ";
    )
    echo " ";
    echo " ";
    )
    echo " ";
    echo " ";
    )
    echo " ";
    ?>


$Employee = array(array(array("name", "company", "year"),
array("id", "skills", "profile"),
array("city", "state", "country")
),
/* array to store the name, company and year of employee*/
array(array("jiya", "Infosys", 2016),
array("ram", "ola", 2017)
),
/* array to store the id, skills and profile of employees */
array(array("E101", "PHP", "developer"),
array("E103", "mysql", "DBA")
),
/* array to store the city, state and country of employees */
array(array("Bangalore", "Karnataka", "India"),
array("San Francisco", "California", "USA")
)
);
?>
echo " ";
for ( $outermost = 0; $outermost < 3; $outermost++ )
(
echo " The outermost number $outermost";
echo " ";
for ( $row_num = 0; $row_num < 2; $row_num++ )
(
echo " Now displaying the row number $row_num";
echo " ";
for ( $col_num = 0; $col_num < 3; $col_num++ )
(
// accessing the array elements in a 3D array
echo " ".$Employee($outermost)($row_num)($col_num)." ";
)
echo " ";
echo " ";
)
echo " ";
echo " ";
)
echo " ";
?>

lähtö:

Yllä oleva esimerkki näyttää selkeästi työntekijän yksityiskohdat ja taitot erittäin käyttäjäystävällisellä tavalla. Se mahdollistaa jokaisen työntekijän yksityiskohdat yksityiskohtaisissa 3D-ryhmissä. Olemme tekemisissä kolmiulotteisten taulukkojen kanssa, jotta päästäksemme siihen meidän on ensin päästävä päämatriisiin ja sitten hakemistoon, joka taas pitää alijoukon, ja sitten sen alaryhmän elementeihin. Tällä tavoin pääsy elementteihin toimii moniulotteisten ryhmien tapauksessa, jotka alkavat uloimmasta sisimpaan ryhmään. samoin, tosielämässä on alimatriiseja tai yksityiskohtaisia ​​asioita, joissa käytetään moniulotteisia matriiseja.

johtopäätös

Yllä oleva selitys osoittaa selvästi, kuinka moniulotteisia taulukkoja käytetään php: ssä niiden perussyntaksin ja alustamisen kanssa. Moniulotteisilla taulukkoilla on tärkeä rooli tosielämäongelmien käsittelyssä, koska niiden avulla käyttäjä voi tallentaa tiedot yksityiskohtaisessa muodossa. Lisäksi, kuten edellä on esitetty, php sallii moniulotteisen datan tallentamisen joko indeksoidussa tai assosiatiivisessa muodossa vaatimusten mukaisesti, mikä tekee ystävällisemmäksi datan käytön ja tallentamisen.

Suositellut artikkelit

Tämä on opas moniulotteiseen taulukkoon PHP: ssä. Tässä keskustellaan deklaraatiosta, moniulotteisen taulukon alustamisesta php: ssä sen tyyppien kanssa. Voit myös katsoa seuraavia artikkeleita saadaksesi lisätietoja -

  1. PHP-taikuusvakiot (työskentely ja esimerkit)
  2. Laravelin 13 tärkeintä ominaisuutta
  3. Socket-ohjelmointi PHP: ssä
  4. Ylikuormitustyypit PHP: ssä
  5. Silmukoita VBScript-ohjelmassa esimerkkien kanssa
  6. Socket-ohjelmointi Pythonissa