Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Handmade Character Soft Toys
anil1961
Updated:
Tuesday at 2:11 PM
Bodim.lk out now !
Manoj Suranga Bandara
Updated:
Sunday at 3:05 AM
Power Lifting Lever Belt
SkullVamp
Updated:
Jun 13, 2026
Ad icon
port.lk Domain for sale
Lankan-Tech
Updated:
Jun 13, 2026
Colombo
Kaduwela - Two Storey House for Sale
dilrasan
Updated:
Jun 11, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
Another PHP problem machan :(
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="Ayeshlive" data-source="post: 15390424" data-attributes="member: 363439"><p>මචන් ඔය ඔතන function එක ඇතුලේ echo කරනවා. ඒ නිසා PHP කරන්නේ ඉස්සරලා name එක print කරන එක. echo එකේ return එකක් නෑ. </p><p></p><p>අනිත් එක global keyword එක use කරන්න කලින් ඒක global scope ekema define කරලා තියෙන්න ඕනේ me widihata:</p><p><a href="http://3v4l.org/9EsTb" target="_blank">http://3v4l.org/9EsTb</a></p><p>[PHP]<?php</p><p>function set_name($name) {</p><p> $GLOBALS['name'] = $name;</p><p>}</p><p></p><p>function get_name() {</p><p> return $GLOBALS['name'];</p><p> /* Above line is equal to:</p><p> * global $name;</p><p> * return $name;</p><p> */</p><p>}</p><p></p><p>function wrap($txt) {</p><p> echo 'Your username is ' . get_name() . ' ' . $txt;</p><p>}</p><p></p><p>/* You should not print/echo stuff in a function. So the better way would be:</p><p> * function wrap($txt) {</p><p> * return 'Your username is ' . get_name() . $txt;</p><p> * }</p><p> * echo wrap($txt)</p><p> */</p><p></p><p> </p><p>// Usage:</p><p></p><p>set_name('Rajitha');</p><p>wrap('tobacco');</p><p>?>[/PHP]</p></blockquote><p></p>
[QUOTE="Ayeshlive, post: 15390424, member: 363439"] මචන් ඔය ඔතන function එක ඇතුලේ echo කරනවා. ඒ නිසා PHP කරන්නේ ඉස්සරලා name එක print කරන එක. echo එකේ return එකක් නෑ. අනිත් එක global keyword එක use කරන්න කලින් ඒක global scope ekema define කරලා තියෙන්න ඕනේ me widihata: [URL]http://3v4l.org/9EsTb[/URL] [PHP]<?php function set_name($name) { $GLOBALS['name'] = $name; } function get_name() { return $GLOBALS['name']; /* Above line is equal to: * global $name; * return $name; */ } function wrap($txt) { echo 'Your username is ' . get_name() . ' ' . $txt; } /* You should not print/echo stuff in a function. So the better way would be: * function wrap($txt) { * return 'Your username is ' . get_name() . $txt; * } * echo wrap($txt) */ // Usage: set_name('Rajitha'); wrap('tobacco'); ?>[/PHP] [/QUOTE]
Insert quotes…
Verification
Haya warak paha keeyada? (haya wadi kireema paha)
Post reply
Top
Bottom