alexarpad2003 Posted October 14, 2011 Report Share Posted October 14, 2011 Avem exemplul asta : <?php$produs = array( "laptop" => "1200 ron", "samsung" => "1000 ron", "lapte" => "5 lei");echo "<table border='1'>";foreach ($produs as $nume => $pret){ echo "<tr>"; echo "<td>"; echo $nume; echo "</td>"; echo "<td>"; echo $pret; echo "</td>"; echo "</tr>";}echo "</table>";?>Cum as putea scrie un array de genul "laptop" => "1200 ron" => "da". Iar foreach-ul sa fie ($produs as $nume => $pret=>$stoc), bineinteles sa adaug si echo "<td>";echo $stoc;echo "</td>";echo "</tr>";Stiu ca nu exista asa ceva, sunt prea obosit si am explicat cum am putut. Deci ce alternative pot gasi la problema mea ? Quote Link to comment Share on other sites More sharing options...
devacanta Posted October 15, 2011 Report Share Posted October 15, 2011 (edited) Uite cateva alternative mai jos care pot sa rezolve multe din problemele tale legate de php .<?php$produse = array( array('intrebare' => 'Unde pot invata php?', 'raspuns' => 'http://php.net', 'multumesc'=>'Multumesc!' ), array('intrebare' => 'Unde pot invata php?', 'raspuns' => 'http://www.lynda.com/PHP-tutorials/php-with-mysql-essential-training/435-2.html', 'multumesc'=>'Multumesc!' ), array('intrebare' => 'Unde pot invata php?', 'raspuns' => 'http://google.com', 'multumesc'=>'Multumesc!' ),);echo "<table border='1'>"; foreach ($produse as $produs) { extract($produs); echo "<tr> <td>$intrebare</td> <td>$raspuns</td> <td>$multumesc</td> </tr>"; } echo "</table>"; ?> Edited October 15, 2011 by devacanta Quote Link to comment Share on other sites More sharing options...
Birkoff Posted October 15, 2011 Report Share Posted October 15, 2011 (edited) $lista = array( 'laptop' => array( 'pret' => 1200, 'stoc' => 'da', ), 'masina' => array( 'pret' => 40000, 'stoc' => 'nu', ), );foreach($lista as $nume=>$val) { echo $nume; echo $val['pret']; echo $val['stoc'];}varianta 2$lista = array( 0 => array( 'nume' => 'laptop', 'pret' => 1200, 'stoc' => 'da', ), 1 => array( 'nume' => 'masina', 'pret' => 40000, 'stoc' => 'da', ), );foreach ($lista as $row) { echo $row['nume']; echo $row['pret']; echo $row['stoc'];} Edited October 15, 2011 by Birkoff 1 Quote Link to comment Share on other sites More sharing options...
alexarpad2003 Posted October 15, 2011 Author Report Share Posted October 15, 2011 Merci + rep Quote Link to comment Share on other sites More sharing options...