Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Tablice i uklad danych
DannyM
post
Post #1





Grupa: Zarejestrowani
Postów: 507
Pomógł: 2
Dołączył: 30.10.2003
Skąd: Poznań

Ostrzeżenie: (10%)
X----


mam taka tablice
Array
(
[name] => Array
(
[0] => Marta
[1] => Jak
)

[nazwisko] => Array
(
[0] => Warta
[1] => Kowalski
)

[email] => Array
(
[0] => marti@ppsdfsd.pl
[1] => kowal@map.pl
)

[password] => Array
(
[0] => chauyec66
[1] => 456tre
)

[Submit] => Zamawiam
)

  1. foreach ($_POST as $klucz => $tablica ) {
  2.  
  3. foreach ($tablica as $nr_wiersza => $wartosc )
  4. echo 'ID: '.$nr_wiersza.' =:'.$wartosc;
  5. }
  6. print "<pre>";
  7. print_r($_POST);
  8. print "</pre>";


Jak przypisac imie do nazwiska itd
Dodatkowo mam Warning: Invalid argument supplied for foreach() in " foreach ($tablica as $nr_wiersza => $wartosc ) "
Dopiero zaczynam z tablicami wiec prosze o wyrozumialosc

Ten post edytował DannyM 17.12.2009, 16:21:18
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
piotrekkr
post
Post #2





Grupa: Zarejestrowani
Postów: 386
Pomógł: 25
Dołączył: 28.09.2005

Ostrzeżenie: (0%)
-----


  1. $srcArray = Array
  2. (
  3. 'name' => Array
  4. (
  5. 0 => 'Marta',
  6. 1 => 'Jak',
  7. ),
  8.  
  9. 'nazwisko' => Array
  10. (
  11. 0 => 'Warta',
  12. 1 => 'Kowalski',
  13. ),
  14.  
  15. 'email' => Array
  16. (
  17. 0 => 'marti@ppsdfsd.pl',
  18. 1 => 'kowal@map.pl',
  19. ),
  20.  
  21. 'password' => Array
  22. (
  23. 0 => 'chauyec66',
  24. 1 => '456tre',
  25. ),
  26. 'Submit' => 'Zamawiam',
  27. );
  28. $destArray = array();
  29. unset($srcArray['Submit']);
  30. foreach($srcArray as $key => $val){
  31. foreach($val as $personId => $personValue){
  32. $destArray[$personId][$key] = $personValue;
  33. }
  34. }
  35. var_dump($destArray);
  36.  


wynik:

Kod
array(2) {
  [0]=>
  array(4) {
    ["name"]=>
    string(5) "Marta"
    ["nazwisko"]=>
    string(5) "Warta"
    ["email"]=>
    string(16) "marti@ppsdfsd.pl"
    ["password"]=>
    string(9) "chauyec66"
  }
  [1]=>
  array(4) {
    ["name"]=>
    string(3) "Jak"
    ["nazwisko"]=>
    string(8) "Kowalski"
    ["email"]=>
    string(12) "kowal@map.pl"
    ["password"]=>
    string(6) "456tre"
  }
}
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 18.10.2025 - 14:28