Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP]Zmiana tablicy
@rtur
post 11.05.2015, 01:37:21
Post #1





Grupa: Zarejestrowani
Postów: 254
Pomógł: 3
Dołączył: 23.02.2006

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


  1. $i = 1;
  2. foreach($elementy as $element){
  3. $dre[] = array( 'element_'.$i++ =>$element['title']);
  4. }
  5. var_dump($dre);

Mam taką pętle foreach która zwraca mi tablice w postaci:
  1. array(2) {
  2. [0]=>
  3. array(1) {
  4. ["element_1"]=>
  5. string(4) "Koty"
  6. }
  7. [1]=>
  8. array(1) {
  9. ["element_2"]=>
  10. string(3) "Psy"
  11. }
  12. }

Jak teraz zmienić ta tablice abym w zmiennej $dre dostał tablicę w postaci:
  1. array('element_1'=>'Koty','element_2'=>'Psy');

?

Ten post edytował @rtur 11.05.2015, 01:38:39


--------------------
Artur
Go to the top of the page
+Quote Post
johny_s
post 11.05.2015, 02:08:19
Post #2





Grupa: Zarejestrowani
Postów: 594
Pomógł: 122
Dołączył: 17.07.2005
Skąd: P-na

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


  1. $dre[ 'element_'.$i++] = $element['title'];
Go to the top of the page
+Quote Post
@rtur
post 11.05.2015, 02:23:21
Post #3





Grupa: Zarejestrowani
Postów: 254
Pomógł: 3
Dołączył: 23.02.2006

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


Dziękuję działa smile.gif

Ten post edytował @rtur 11.05.2015, 02:27:06


--------------------
Artur
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 27.04.2024 - 04:35