Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] problem z foreach
lled3
post
Post #1





Grupa: Zarejestrowani
Postów: 91
Pomógł: 0
Dołączył: 7.12.2007

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


  1. <?php
  2. print_r($temp);
  3.  $temp2=Array();
  4. if( count( $wartosc ) > 0 )
  5. //przenumerowanie kluczy
  6. foreach($temp as $klucz => $wartosc)
  7. {
  8. $temp2 = $wartosc;
  9. }
  10. print_r($temp2);
  11. ?>


pierwsze print_r wyswietla:

Kod
Array (     [5] => Array         (             [tag] => duży             [ile] => 10.5         )      [2] => Array         (             [tag] => lew             [ile] => 5.6         )      [1] => Array         (             [tag] => olbrzymi             [ile] => 5         )      [11] => Array         (             [tag] => cichy             [ile] => 4.8         )      [4] => Array         (             [tag] => smok             [ile] => 4         )      [3] => Array         (             [tag] => samochód             [ile] => 4         )      [13] => Array         (             [tag] => spokojny             [ile] => 2.4         )      [8] => Array         (             [tag] => malinka             [ile] => 2         )      [0] => Array         (             [tag] => auto             [ile] => 2         )      [6] => Array         (             [tag] => kiwi             [ile] => 1.6         )      [10] => Array         (             [tag] => owoc             [ile] => 1.4         )      [14] => Array         (             [tag] => kolczatka             [ile] => 1         )      [7] => Array         (             [tag] => tygrys             [ile] => 1         )      [9] => Array         (             [tag] => krokodyl             [ile] => 1         )      [12] => Array         (             [tag] => kangur             [ile] => 1         )  )


drugie

Kod
Array ( )


a chaielm zeby przenumerowalo klucze

Ten post edytował lled3 7.08.2008, 19:05:18
Go to the top of the page
+Quote Post
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




nie: $temp2 = $wartosc;
a: $temp2[] = $wartosc;


pozatym caly twoj kod mozna zmiescic w jednej linijce:
  1. <?php
  2. $temp2 = array_values($temp);
  3. ?>

Nie wymyslaj koła na nowo (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
Go to the top of the page
+Quote Post
lled3
post
Post #3





Grupa: Zarejestrowani
Postów: 91
Pomógł: 0
Dołączył: 7.12.2007

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


dzięki nospor (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)
ile to już lat my sie znamy (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) ?
Go to the top of the page
+Quote Post

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: 23.08.2025 - 04:05