Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Array rekurencyjne wpisywanie wartosci
adamli
post
Post #1





Grupa: Zarejestrowani
Postów: 40
Pomógł: 0
Dołączył: 18.07.2008

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


Mam tablice:
  1. $matchArray = array(
  2. 18 => array("name"=>'vin',"value"=>"","parent"=>"vehicle"),
  3.  
  4. 51 => array("name"=>'damages',"value"=>
  5. array("name"=>'damage',"value"=>
  6. array("name"=>'fixed',"value"=>"","parent"=>"damage")
  7. ,"parent"=>"damages")
  8. ,"parent"=>"vehicle"),
  9.  
  10. );


Teraz musze wszedzie gdzie value nie jest tablica wstawic jakas wartosc...
Wartosc ta jest roznie zaglebiona dlatego tez uzywam funkcji rekurencyjnej
setvalue(). Niestety to co jest w linijce 5 tej funkcji sie nie wykonuje...

dla tej tablicy powinno dzialac jak:$matchArray[51]["value"]["value"]["value"] = "costam2";
niestety nie dziala... czy pomoze tu jakies zastosowanie referencji ?


  1. 1.function setvalue($value,$array){
  2. 2. if(is_array($array["value"])){
  3. 3. setvalue($value,&$array["value"]) ;
  4. 4. }else {
  5. 5. $array["value"] = "costam2";
  6. 6. }
  7. 7.};
  8. 8.
  9. 9. foreach ($matchArray as $key =>$value) {
  10. 10. if (is_array($value["value"])){
  11. 11. setvalue(1,$value["value"]) ;
  12. 12. }else
  13. 13. $matchArray[$key]["value"] = "costam1";
  14. 14. };


Z gory dziekuje za odpowiedz.
Adam
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
nospor
post
Post #2





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




zapomniales o jeszcze jednym &
foreach ($matchArray as $key =>&$value)

Go to the top of the page
+Quote Post
adamli
post
Post #3





Grupa: Zarejestrowani
Postów: 40
Pomógł: 0
Dołączył: 18.07.2008

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


chyba jeszcze gdzies bo nie dziala...
Go to the top of the page
+Quote Post
nospor
post
Post #4





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




  1. function setvalue($value,&$array){
  2. if(is_array($array["value"])){
  3. setvalue($value,&$array["value"]) ;
  4. }else {
  5. $array["value"] = "costam2";
  6. }
  7. };
  8.  
  9. foreach ($matchArray as $key =>&$value) {
  10. if (is_array($value["value"])){
  11. setvalue(1,$value["value"]) ;
  12. }else
  13. $matchArray[$key]["value"] = "costam1";
  14. };

działa (IMG:style_emoticons/default/smile.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: 24.08.2025 - 21:49