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
strife
post
Post #2





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

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: 8.10.2025 - 10:45