Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Jak pobrać w funkcji nazwę zmiennej?
tomeksromek
post
Post #1





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 14.03.2008

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


  1. <?php
  2. function __test($name){
  3. echo blabal . '|' . $name ."<br >";
  4. }
  5.  
  6. $ela = "zapendowska";
  7. __test($ela);
  8. // żeby zwróciło:
  9. // ela zapendowska
  10. ?>


Macie jakieś pomysły?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
kszychu
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 2 712
Pomógł: 23
Dołączył: 27.10.2003
Skąd: z kontowni

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


  1. <?php
  2. function __test($name){
  3. echo $name . '|' . $$name ."<br >";
  4. }
  5. $zmienna = 'ela';
  6. $$ela = "zapendowska";
  7. __test($zmienna);
  8. ?>


--------------------
"Coś się kończy, coś się zaczyna." Andrzej Sapkowski
Go to the top of the page
+Quote Post
strife
post
Post #3





Grupa: Przyjaciele php.pl
Postów: 2 605
Pomógł: 96
Dołączył: 22.10.2004
Skąd: UK

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


  1. <?php
  2. function getVarName (& $iVar, & $aDefinedVars) {
  3.  foreach ($aDefinedVars as $k => $v) {
  4.  $aDefinedVars_0[$k] = $v;
  5.  }
  6.  
  7.  $iVarSave = $iVar;
  8.  $iVar  = !$iVar;
  9.  
  10.  $aDiffKeys = array_keys (array_diff_assoc ($aDefinedVars_0, $aDefinedVars));
  11.  $iVar = $iVarSave;
  12.  
  13.  return $aDiffKeys[0];
  14. }
  15.  
  16. $ela = " zapendowska";
  17.  
  18. // zwraca `ela`
  19. // echo getVarName($ela, get_defined_vars()); 
  20.  
  21. // zwroci `ela zapendowska`
  22. $returnString = getVarName($ela, get_defined_vars()) . $ela; 
  23. echo $returnString;
  24.  
  25.  
  26. ?>


Na podstawie: http://mach13.com/php/how-to-get-a-variabl...-string-in-php/.


--------------------
Go to the top of the page
+Quote Post
tomeksromek
post
Post #4





Grupa: Zarejestrowani
Postów: 3
Pomógł: 0
Dołączył: 14.03.2008

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


strife, dzięki wielkie !

Ten post edytował tomeksromek 17.03.2008, 15:26:46
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 Aktualny czas: 21.08.2025 - 11:07