Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> funkcja w stringu
andreu2311
post
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 25.10.2008

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


Witam, mam pewien problem z dodaniem wartości zwracanej przez funkcję do stringu.
Otóż zgodnie z tym co jest opisane na php.net , napis echo powinien zwrócić wartość zwracaną
przez funkcje, niestety nic się nie wyświetla. Wie ktoś może dlaczego?

<?php
function getName()
{
$a = 'ddd';
return a;
}

$b = 'b';
echo "This is the value of the var named by the return value of getName(): {${getName()}}";


?>
Go to the top of the page
+Quote Post
Spawnm
post
Post #2





Grupa: Moderatorzy
Postów: 4 069
Pomógł: 497
Dołączył: 11.05.2007
Skąd: Warszawa




np:
  1. <?php
  2. function getName()
  3. {
  4. $a = 'ddd';
  5. return $a;
  6. }
  7.  
  8. $massage=gatName();
  9. echo $massage;
  10. ?>


przy return nie miałeś '$'.
Go to the top of the page
+Quote Post
andreu2311
post
Post #3





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 25.10.2008

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


no tak, niestety kod dalej nie dziala, mi chodzi generalnie o to:

echo "This is the value of the var named by the return value of getName(): {${getName()}}";
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




Cytat
Otóż zgodnie z tym co jest opisane na php.net
Daj linka gdzie ten kod znalazles bo albo:
1) piszą tam wierutne bzdury
2) przepisales z bledem
lub
3) sam to na podstawie czegos wymysliles i zrobiles conajmniej dwa bledy smile.gif
lub
4) oni tak mają na stronie i to oni mają tam conajmniej dwa bledy winksmiley.jpg


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
andreu2311
post
Post #5





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 25.10.2008

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


http://www.php.net/manual/en/language.types.string.php
Go to the top of the page
+Quote Post
nospor
post
Post #6





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




no i tam nie ma tak blednego kodu winksmiley.jpg

  1. <?php
  2. function getName()
  3. {
  4. $a = 'ddd';
  5. return $a;
  6. }
  7.  
  8. $ddd = 'b';
  9. echo "This is the value of the var named by the return value of getName(): {${getName()}}";
  10. ?>


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
andreu2311
post
Post #7





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 25.10.2008

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


czyli jak?, mi na tym głównie zależało, żeby to co funkcja zwraca dodać do stringa, funkcje sam zrobiłem. echo "This is the value of the var named by the return value of getName(): {${getName()}}";

Ten post edytował andreu2311 18.02.2009, 23:38:48
Go to the top of the page
+Quote Post
nospor
post
Post #8





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




Cytat
żeby to co funkcja zwraca dodać do stringa,

ja ci podalem jak do stringa to co zawiera zmienna, o nazwie takiej, jaka zwraca funkcja.

A jak ty chcesz dodac tylko to co zwraca funkcja to:
  1. <?php
  2. function getName()
  3. {
  4. $a = 'ddd';
  5. return $a;
  6. }
  7.  
  8. echo "to co zwraca getName(): ".getName();
  9. ?>

I juz.


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

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 - 08:25